I have two 0D numpy arrays and want to check if they are same class. The first one y1 is obtained by matmul two 1D arrays; and the second y2 is obtained by squeezing a 1D array.
import numpy as np
y1 = np.array([1]) @ np.array([5])
y2 = np.array([3]).squeeze()
y1.ndim == y2.ndim == 0 # -> True
y1.__class__ is np.ndarray # -> False
y2.__class__ is np.ndarray # -> True
as shown above, y1 and y2 are both 0D.
If y1 is not a ndarray, what is it?
In my actual case, y1 is just matmul of two numpy arrays, whose output can be a numpy array, or not, as show above; y2 come from some other operations, whose output should be same class as y1, so I have an assertion: assert y1.__class__ is y2.__class__. and this fails when y1 is matmul of two 1D arrays. What should I do then? Thanks!