Certain functions in Numpy return a 2d matrix as output. but I want them to be in 2d array form. What is the most efficient (memory and cpu) way to convert a 2d matrix to a 2d array?
1 Answer
Note that a numpy.matrix is already an ndarray subclass, and nothing more than a specialized 2D array. Hence you're most likely quite alright without converting your matrix to an explicit numpy.array unless you have a particular reason to do so, perhaps the additional generality of a Numpy array.
Should this be the case, you can convert your matrix to an array with numpy.asarray(). It's important you use this method and not numpy.asanyarray() in your case as with numpy.asanyarray() allows subclasses of ndarray to pass through, as your matrix would.