We have indeed been using "type(a) is np.ndarray" in Theano to check that. If there's a better way, I'm interested to know as well :)
-=- Olivier 2011/12/7 <[email protected]> > If I want to know whether something that might be an array is really a > plain ndarray and not a subclass, is using `type` the safest bet? > > All the other forms don't discriminate against subclasses. > > >>> type(np.ma.zeros(3)) is np.ndarray > False > >>> type(np.zeros(3)) is np.ndarray > True > > >>> isinstance(np.ma.zeros(3), np.ndarray) > True > >>> isinstance(np.zeros(3), np.ndarray) > True > > >>> issubclass(np.ma.zeros(3).__class__, np.ndarray) > True > >>> issubclass(np.zeros(3).__class__, np.ndarray) > True > > >>> isinstance(np.matrix(np.zeros(3)), np.ndarray) > True > >>> type(np.matrix(np.zeros(3))) is np.ndarray > False > > Thanks, > > Josef > _______________________________________________ > NumPy-Discussion mailing list > [email protected] > http://mail.scipy.org/mailman/listinfo/numpy-discussion >
_______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
