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

前端 未结 4 1754
天涯浪人
天涯浪人 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 06:03

    In Python, (length,) is a tuple, with one 1 item. (length) is just parenthesis around a number.

    In numpy, an array can have any number of dimensions, 0, 1, 2, etc. You are asking about the difference between 1 and 2 dimensional objects. (length,1) is a 2 item tuple, giving you the dimensions of a 2d array.

    If you are used to working with MATLAB, you might be confused by the fact that there, all arrays are 2 dimensional or larger.

提交回复
热议问题