one-dimensional array shapes (length,) vs. (length,1) vs. (length)

前端 未结 4 1758
天涯浪人
天涯浪人 2020-12-31 05:25

When I check the shape of an array using numpy.shape(), I sometimes get (length,1) and sometimes (length,). It looks like the differe

4条回答
  •  庸人自扰
    2020-12-31 05:40

    A vector in Python is actually a two-dimensional array. It's just a coincidence that the number of rows is 1 (for row vectors), or the number of columns is 1 (for column vectors).

    By contrast, a one-dimensional array is not a vector (neither a row vector nor a column vector). To understand this, think a concept in geometry, scalar. A scalar only has one attribute, which is numerical. By contrast, a vector has two attributes, number and direction. Fortunately, in linear algebra, vectors also have "directions", although only two possible directions - either horizontal or vertical (unlike infinite possible directions in geometry). A one-dimensional array only has numerical meaning - it doesn't show which direction this array is pointing to. This is why we need two-dimensional arrays to describe vectors.

提交回复
热议问题