码迷,mamicode.com
首页 > 编程语言 > 详细

array创建数组

时间:2020-03-27 21:48:23      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:copy   order   strong   一维数组   style   div   alt   语法   使用   

  • 语法格式

 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.]]]

 

array创建数组

标签:copy   order   strong   一维数组   style   div   alt   语法   使用   

原文地址:https://www.cnblogs.com/monsterhy123/p/12584304.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!