摘要: 1 #导入numpy模块 2 import numpy as np 3 #创建一维数组 4 a = np.arange(1,13) 5 print(a) 6 #对一维数组进行修改形状 (4,3) 7 a = a.reshape(4,3) #形成二维数组 8 print(a) 9 #索引的使用 10 阅读全文
posted @ 2020-03-29 22:49 小他_W 阅读(2528) 评论(0) 推荐(2) 编辑
摘要: ndarray 对象的内容可以通过索引或切片来访问和修改,与 Python 中 list 的切片操作一样。 ndarray 数组可以基于 0 - n 的下标进行索引,并设置 start, stop 及 step 参数进行,从原数组中切割出一个新数组。 代码 1 #导入numpy模块 2 import 阅读全文
posted @ 2020-03-29 22:19 小他_W 阅读(766) 评论(0) 推荐(0) 编辑
摘要: 1 #导入numpy模块 2 import numpy as np 3 #zeros 4 def zerosTest(): 5 a = np.zeros(5) 6 print(a) 7 #指定类型 8 b = np.zeros((5,),dtype=int) 9 print(b) 10 #创建二维数 阅读全文
posted @ 2020-03-29 21:52 小他_W 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 1 #导入numpy 2 import numpy as np 3 #创建一维数组 4 a = np.array([1,2,3,4]) 5 print(a) 6 #创建二维数组 7 b = np.random.randint(4,10,size=(2,3)) 8 print(b) 9 #创建三维数组 阅读全文
posted @ 2020-03-29 21:22 小他_W 阅读(217) 评论(0) 推荐(0) 编辑