Hi,
I was trying to prevent array creation from iterating over instances of classes
implementing __iter__, __getitem__, __len__ etc.
An effective way (at least with a UserDict subclass) seem setting
__array_interface__ = {"shape": (), "typestr": "O"} # with data field omitted
(!)
According to the docs
https://numpy.org/devdocs/reference/arrays.interface.html#object.__array_interface__
"Not specifying this field uses a “scalar” path that we may remove in the
future as we are not aware of any users."
I am new to __array_interface__, so this might be a bad approach (*). If not,
this seems to be a good reason for *not* removing.
Note there is demand for avoiding coercion of custom types into new dimensions:
https://stackoverflow.com/q/43722023
https://stackoverflow.com/q/70460738
https://stackoverflow.com/q/22290204
https://github.com/numpy/numpy/issues/27212
https://github.com/numpy/numpy/issues/27382
(*) Still, other attempts partially messed up with class functionality (e.g.,
__len__ = None) or did not work at all:
__iter__ = None (TypeError: Could not convert object to sequence)
implementing __array__ (RecursionError: maximum recursion depth exceeded)
Cheers,
Marco
_______________________________________________
NumPy-Discussion mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/numpy-discussion.python.org
Member address: [email protected]