1

Consider the following vector:

import numpy as np

u = np.random.randn(5)
print(u)

[-0.30153275 -1.48236907 -1.09808763 -0.10543421 -1.49627068]

When we print its shape:

print(u.shape)
(5,)

I was told this is neither a column vector nor a row vector. So what is essentially this shape is in numpy (m,) ?

moth
  • 1,833
  • 12
  • 29
  • this is on element in `tuple`. For one elelment in tuple we show like this : (1,), two elelemt : (1,2) , ... – I'mahdi Sep 19 '21 at 12:40
  • This answer might help: https://stackoverflow.com/a/12876194/13354437 – Almog-at-Nailo Sep 19 '21 at 12:46
  • 1
    Strictly speaking, a multidimensional array is just an array where you use multiple dimensions to reach an element. There's no inherent row or column there. An array with shape (m,) has 1 dimension of length m, that's it. Now by *convention*, we treat shapes of (m,) or (1,m) as row vectors and shapes of (m,1) as column vectors, and that's how it's even printed. We just needed to pick some dimension for rows and some dimension for columns. But sometimes this convention is discarded, and what strictly should be a column vector is represented by a (m,) array. – BatWannaBe Sep 19 '21 at 12:50

1 Answers1

0
# one-dimensional array (rank 1 array)
# array([ 0.202421  ,  1.04496629, -0.28473552,  0.22865349,  0.49918827])
a = np.random.randn(5,) # or b = np.random.randn(5)

# column vector (5 x 1)
# array([[-0.52259951],
#       [-0.2200037 ],
#       [-1.07033914],
#       [ 0.9890279 ],
#       [ 0.38434068]])
c = np.random.randn(5,1)

# row vector (1 x 5)
# array([[ 0.42688689, -0.80472245, -0.86294221,  0.28738552, -0.86776229]])
d = np.random.randn(1,5)

For example (see docs):

numpy.dot(a, b)
  • If both a and b are 1-D arrays, it is inner product of vectors (without complex conjugation).
  • If both a and b are 2-D arrays, it is matrix multiplication
lamsal
  • 121
  • 1
  • 3
  • 14