Reputation: 388
I was playing around with numpy matrices to learn more about sub-matrices. Below is the result which I got when I tried to extract a row vector and a column vector:
>>> import numpy as np
>>> x = np.zeros(shape=(8,9))
>>> x
array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
>>> y = x[:, 0]
>>> y
array([ 0., 0., 0., 0., 0., 0., 0., 0.])
>>> z = x[0, :]
>>> z
array([ 0., 0., 0., 0., 0., 0., 0., 0., 0.])
The thing is that both row vector and column vector are shown in same fashion. So I don't know whether they are treated as same or different.
Upvotes: 2
Views: 129
Reputation: 250961
You're currently fetching only a single row/column from the array, so that's the best way to represent a 1-D view of the row/column returned.
Use slicing to get results like this:
In [16]: x[:,:1]
Out[16]:
array([[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.]])
In [17]: x[:1,:]
Out[17]: array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
Upvotes: 2