Alan G Isaac <alan.isaac <at> gmail.com> writes: [clip] > Here, quacking is behaving like an ndarray (in your view, > as I understand it) when asked. But how do we ask? > Your view (if I understand) is we ask via the operations > supported by ndarrays. But maybe that is the wrong way > for the library to ask this question.
It is not a good thing that there is no well defined "domain specific language" for matrix algebra in Python. Rather, some code is written with one convention and other code with a different convention. The conventions disagree on how to express basic operations, such as matrix multiplication. Moreover, the ndarray is also lacking some useful things, as you point out. But I think the right solution would be to stuff the required additions into ndarray, rather than retaining the otherwise incompatible np.matrix as a crutch. > If so, then scipy libraries could ask an object > to behave like an an ndarray by calling, e.g., > __asarray__ on it. It becomes the responsibility > of the object to return something appropriate > when __asarray__ is called. Objects that know how to do > this will provide __asarray__ and respond > appropriately. Another way to achieve similar thing as your suggestion is to add a coercion function in the vein of scipy.sparse.aslinearoperator. It could deal with known-failure cases (np.matrix, scipy.sparse matrices) and for the rest just assume the object satisfies the ndarray API and pass them through. -- Pauli Virtanen _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion