1. 官文链接:[https://numpy.org/doc/stable/reference/generated/numpy.ndarray.shape.html#numpy.ndarray.shape](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.shape.html#numpy.ndarray.shape)

    元组数组大小,官文里面没给出什么有价值的信息,只能知道numpy.reshape这个有一些修改shape的用处。以下都是自己个人探究。

    元组中数值的数量控制着数组的维度。

    1. import numpy as np
    2. tuple1=(1)
    3. tuple2=(1,2)
    4. tuple3=(1,2,3)
    5. tuple4=(1,2,3,4)
    6. #一维
    7. b1 = np.ndarray((tuple1) ,dtype='int32')
    8. print(b1)
    9. print('----------------------------------------------------')
    10. #二维
    11. b1 = np.ndarray((tuple2) ,dtype='int32')
    12. print(b1)
    13. print('----------------------------------------------------')
    14. #三维
    15. b1 = np.ndarray((tuple3) ,dtype='int32')
    16. print(b1)
    17. print('----------------------------------------------------')
    18. #四维
    19. b1 = np.ndarray((tuple4) ,dtype='int32')
    20. print(b1)

    当使用的元组有两个数值时:

    1. import numpy as np
    2. tuple1=(1,2)
    3. tuple2=(3,4)
    4. #当元组中有两个数值时,第一个参数控制有几组数组,第二个控制每组数组包含多少数值
    5. b1 = np.ndarray((tuple1) ,dtype='int32')
    6. print(b1)
    7. print('----------------------------------------------------')
    8. b1 = np.ndarray((tuple2) ,dtype='int32')
    9. print(b1)

    当使用的元组有三个数值时,大于三个数值时方法相同,都是按照第一个参数不断向上一个维度判断有几个数组块:

    1. import numpy as np
    2. tuple1=(1,2,3)
    3. tuple2=(3,2,3)
    4. #当元组中有两个数值时,第一个参数控制当前数组块,在上一个维度中有几个,第二个参数控制有几组数组,第三个控制每组数组包含多少数值
    5. b1 = np.ndarray((tuple1) ,dtype='int32')
    6. print(b1)
    7. print('----------------------------------------------------')
    8. b1 = np.ndarray((tuple2) ,dtype='int32')
    9. print(b1)