On Mi, 2015-09-30 at 09:11 -0700, Chris Barker wrote: > On Tue, Sep 29, 2015 at 6:35 PM, Charles R Harris > <charlesr.har...@gmail.com> wrote: > For this, and other use-cases, special casing > Numpy arrays stored in object arrays does make > sense: > > > "If this is s a Numpy array, pass the > operation through." > > > Because we now (development) use rich compare, the > result looks like > > > Oops, not what was intended. In fact it raises an error > > In [7]: b > Out[7]: array([array([ 1., 1., 1.]), array([-1., -1., > -1.])], dtype=object) > > In [8]: sign(b) > > --------------------------------------------------------------------------- > ValueError Traceback (most > recent call last) > <ipython-input-8-3b1a81271d2e> in <module>() > ----> 1 sign(b) > > ValueError: The truth value of an array with more than one > element is ambiguous. Use a.any() or a.all() > > > exactly -- it seems to me that a special case for numpy arrays as > objects in object arrays makes sense, so you'd get: > > > In [6]: oa > Out[6]: > array([[1.0, 1.0, 1.0], > [-1.0, -1.0, -1.0]], dtype=object) > > > In [7]: np.sign(oa) > Out[7]: > array([[1, 1, 1], > [-1, -1, -1]], dtype=object) > > > (which you do now in the version I'm running). > > > Though rather than the special case, maybe we really need > dtype=ndarray arrays? >
I think this (as a dtype) is an obvious solution. The other solution, I am not sure about in general to be honest. We may have to be more careful about creating a monster with new dtypes, rather than being careful to implement all possible features ;). It is not that I think we would not have consistent rules, etc. it is just that we *want* to force code to be obvious. If someone has arrays inside arrays, maybe he should be expected to specify that. It actually breaks some logic (or cannot be implemented for everything), because we have signatures such as `O->?`, which does not support array output. - Sebastian > > oa = np.array([a1, a2], dtype=np.ndarray) > > > > Then we could count on everything in the array being an array..... > > > -CHB > > > -- > > Christopher Barker, Ph.D. > Oceanographer > > Emergency Response Division > NOAA/NOS/OR&R (206) 526-6959 voice > 7600 Sand Point Way NE (206) 526-6329 fax > Seattle, WA 98115 (206) 526-6317 main reception > > chris.bar...@noaa.gov > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > https://mail.scipy.org/mailman/listinfo/numpy-discussion
signature.asc
Description: This is a digitally signed message part
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion