Hi, I'm having some difficulty understanding how these work and would be grateful for any help. In the simple case, I get what I expect: In [42]: a = np.zeros((), dtype=[('f1', 'f8'),('f2', 'f8')]) In [43]: a == a Out[43]: True If one of the fields is itself an array, and the other is a scalar, the shape of the truth value appears to be based on the comparison of that array, ignoring the scalar: In [44]: a = np.zeros((), dtype=[('f1', 'f8', 8),('f2', 'f8')]) In [45]: a == a Out[45]: array([ True, True, True, True, True, True, True, True], dtype=bool) If the scalar is different, then the shape is from the array, but the truth value is from the scalar: In [46]: b = a.copy() In [47]: b['f2'] = 3 In [48]: a == b Out[48]: array([False, False, False, False, False, False, False, False], dtype=bool) If there are two arrays, it blows up, even comparing to itself: In [49]: a = np.zeros((), dtype=[('f1', 'f8', 8),('f2', 'f8', 2)]) In [50]: a == a --------------------------------------------------------------------------- ValueError Traceback (most recent call last) /home/mb312/<ipython console> in <module>() ValueError: shape mismatch: objects cannot be broadcast to a single shape Is this all expected by someone? Thanks a lot, Matthew
2009/3/7 Matthew Brett <matthew.brett@gmail.com>:
If there are two arrays, it blows up, even comparing to itself:
In [49]: a = np.zeros((), dtype=[('f1', 'f8', 8),('f2', 'f8', 2)])
I wonder what the best approach would be. To return a structured array with the same fields, but dtype changed to bool? Stéfan
participants (2)
-
Matthew Brett -
Stéfan van der Walt