array创建数组

  • 语法格式

 1 numpy.array(object, dtype = None, copy = True, order = None, subok = False, ndmin = 0) 

  • 参数

  • 代码
 1 #导入numpy模块
 2 import numpy as np 
 3 #使用array函数创建一维数组
 4 a = np.array([1,2,3,4])
 5 print(a)
 6 print(type(a))
 7 print("*************************")
 8 
 9 #使用array函数创建二维数组
10 b = np.array([[1,2,3],[4,5,6],[7,8,9]])
11 print(b)
12 print(type(b))
13 print("*************************")
14 
15 #使用array函数创建三维数组
16 c = np.array([[[1,2,3],[4,5,6],[7,8,9]]])
17 print(c)
18 print(type(c))
19 print("*************************")
20 
21 #array函数中dtype的使用
22 d = np.array([3,4,5],dtype=float)
23 print(d)
24 print(type(d))
25 print("*************************")
26 
27 #array函数中ndim的使用
28 e = np.array([4,5,6],dtype=float,ndmin=3)
29 print(e)
 1 [1 2 3 4]
 2 <class 'numpy.ndarray'>
 3 *************************
 4 [[1 2 3]
 5  [4 5 6]
 6  [7 8 9]]
 7 <class 'numpy.ndarray'>
 8 *************************
 9 [[[1 2 3]
10   [4 5 6]
11   [7 8 9]]]
12 <class 'numpy.ndarray'>
13 *************************
14 [3. 4. 5.]
15 <class 'numpy.ndarray'>
16 *************************
17 [[[4. 5. 6.]]]

正是江南好风景
原文地址:https://www.cnblogs.com/monsterhy123/p/12584304.html