Re: [Numpy-discussion] Help needed with the priority of 0d-arrays and np.scalars
Sorry to bump my own post, I know it's rude... However, I'm in dire need for some pointers: what are the priority rules when multiplying numpy scalars and 0d ndarrays ? Thanks a lot in advance
Pierre GM wrote:
Sorry to bump my own post, I know it's rude...
However, I'm in dire need for some pointers: what are the priority rules when multiplying numpy scalars and 0d ndarrays ?
Thanks a lot in advance _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Hmm... I'm not 100% sure off the top of my head, but I would say that 0d arrays should determine the type coercion if any and the returned thing should be a numpy scalar. -Travis
On Tuesday 30 September 2008 17:18:13 Travis E. Oliphant wrote:
Hmm... I'm not 100% sure off the top of my head, but I would say that 0d arrays should determine the type coercion if any and the returned thing should be a numpy scalar.
Travis, I'm afraid I don't understand. According to you, a 0d array should always have the priority on a numpy scalar, right ? That doesn't seem to be the case: ma.masked is a 0d ndarray with a np.float64 dtype and a __array__priority__ of 15. It implements special __mul__ and __rmul__ methods. The multiplication `ma.masked * np.float64(1)` calls `ma.masked.__mul__`, as it should. The multiplication `np.float64(1)*ma.masked` doesn't call `ma.masked.__mul__` nor `ma.masked.__rmul__`. However, `np.float32(1)*ma.masked` does. How could I force `np.float64(1)*ma.masked` to call the proper method ?
participants (2)
-
Pierre GM
-
Travis E. Oliphant