Simplicity and directness in the eye of the beholder.
In [35]: a = np.array([[1],[2],[3]]) In [36]: a.flags Out[36]: C_CONTIGUOUS : True F_CONTIGUOUS : False OWNDATA : True WRITEABLE : True ALIGNED : True UPDATEIFCOPY : False In [37]: b=np.array([1,2,3]).reshape(3,1) In [38]: b.flags Out[38]: C_CONTIGUOUS : True F_CONTIGUOUS : False OWNDATA : False WRITEABLE : True ALIGNED : True UPDATEIFCOPY : False
The first is shorter and owns its data. Thus, in a sense, extra brackets are pain, but it is rather subjective.
Or, if you want something more like MATLAB, you can use the np.matrix string np.matrix :
c=np.array(np.matrix('1;2;3')) c=np.mat('1;2;3').A
But I usually don't worry about the OWNDATA flag. One of my favorite sample arrays:
np.arange(12).reshape(3,4)
Other methods:
np.atleast_2d([1,2,3]).T np.array([1,2,3],ndmin=2).T a=np.empty((3,1),int);a[:,0]=[1,2,3]
hpaulj
source share