[Numpy-discussion] As any array, really any array

Luis Pedro Coelho lpc@cmu....
Mon Aug 15 21:42:43 CDT 2011


Hello all,

I often find myself writing the following code:

    try:
        features = np.asanyarray(features)
    except:
        features = np.asanyarray(features, dtype=object)

I basically want to be able to use fany indexing on features and, in most 
cases, it will be a numpy floating point array. Otherwise, default to having it 
be an array of dtype=object.

Is there a more elegant way to do it with numpy?

Thank you,
-- 
Luis Pedro Coelho | Carnegie Mellon University | http://luispedro.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110815/2efb9b19/attachment.bin 


More information about the NumPy-Discussion mailing list