search

Home  >  Q&A  >  body text

python - 怎么理解numpy的axis?

1.假如我有一个二维数组:

[[0,1,2],[3,4,5],[6,7,8],[9,10,11]]

那么这里的轴axis怎么理解。axis在上面的数组中最大是多少。我没有看懂英文的教程,请详细解释一下。谢谢。

ringa_leeringa_lee2769 days ago445

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 09:33:08

    This is a 2-dimensional array...
    The axis must be 0 or 1

    reply
    0
  • 阿神

    阿神2017-04-18 09:33:08

    You are two-dimensional
    Learn linear algebra

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:33:08

    axis means axis, number axis, and
    corresponds to the dimension in a multi-dimensional array.
    Your example is a 4 x 3 two-dimensional array with 2 axes: axis 0 and axis 1


    >>> import numpy as np
    >>> a = np.array([[0,1,2],[3,4,5],[6,7,8],[9,10,11]])
    >>> a
    array([[ 0,  1,  2],
           [ 3,  4,  5],
           [ 6,  7,  8],
           [ 9, 10, 11]])
    >>> a.shape
    (4, 3)
    >>> a.ndim
    2
    >>> 

    reply
    0
  • Cancelreply