Closed Teschl closed 4 months ago
The MATLAB code has a bunch of similar methods defined for GRIDobj
, so this makes sense to implement in the Python package. Multiplication and division of GRIDobj
are defined elementwise, which I think is how NumPy arrays work by default.
NumPy also has some guidance on making array-like objects work well with the NumPy interface, which seems like it could be a good idea to figure out, so we can get access to a lot of NumPy functions for free.
Since we probably will want to be able to stuff like
dem3 = dem1 + dem2
we should "magic functions" to our class. For each operation, like add(self, other) in the case before, we'll need the normal version (e.g.__add__
) , the reflected versiondem1 = dem2 + some_np_array
(__radd__
) and the augmented versiondem1 += dem2
(__iadd__
). We'll probably also need stuff likelen()
.Most of these will only be wrappers of the already existing numpy logic.
__cmp__
(stuff like<, ==, !=, [..]
)__add__
__sub__
__mul__
__div__
__and__
__or__
__xor__
__len__
__iter__
(so it can be used in for loops)__getitem__
(so the np.array can get accessed withdem[i]
)__setitem__
__delitem__
__array__
(so dem can be passed directly into plt.plot(dem))For most of these, including the
r
andi
version. Here are all the special method names, and here a more readable version.