Note that scalars and arrays are very different from numpy. np.complex64 (this is a 32-bit float, just to be noted, not double precision). You cannot change such an array, you will need to subclass the array and then override it __add__ and __sub__ .
If thatβs all you want to do, it should just work in reverse order http://docs.scipy.org/doc/numpy/user/basics.subclassing.html , since subclassing the array is not so simple.
However, if you want to use this type also as a scalar. For example, you want to index scalars, this is getting harder, at least for the time being. You can get a little more by specifying __array_wrap__ to convert scalars to your own scalar type for some reduction functions, so that indexing works in all cases, it seems to me that you can define your own __getitem__ at the moment.
In all cases, with this approach, you are still using a complex data type, and all functions that are not explicitly overridden will still behave the same. @ecatmur mentioned that you can create new data types from the C side if this is really what you want.
source share