The real magic happens when you ducktype, and ensure your function
works both for arrays and scalars on its own. This is more often
possible than you might think! If you really need, e.g., the shape,
you can do `getattr(input, 'shape', ())` and things may well work for
scalars, and also for objects that behave somewhat like arrays ("duck
arrays").

If you do go for coercion, I agree with Eric' comment about
`np.asanyarray` - it may now just work for `MaskedArray` (but not for,
e.g., SparseArray; that needs real duck-typing).

All the best,

Marten
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion

Reply via email to