摘要:
import numpy as np import random import time a = [] for i in range(10000000): a.append(random.random()) # list t1 = time.time() sum1 = sum(a) t2 = time.time() print("time_list:", (t2-t1)) # numpy... 阅读全文
摘要:
""" ndarray的属性(dtype,shape,ndim,size,itemsize) """ import numpy as np # 创建维度3x3的ndarray数组 data = np.array([[1, 1, 1], [2, 2, 2], [3, 3, 3]]) # 打印属性 print("形状:", data.shape) print("维数:", data.ndim... 阅读全文
摘要:
""" 查看数据类型并修改操作 """ import numpy as np print(" 常用数据类型 ") # 默认整数int32,小数float64 a = np.array([1, 1, 1]) b = np.array([1., 1, 1]) c = np.array([1, 1, 1], dtype=np.float32) d = np.array([1, 1, 1], dtype= 阅读全文
摘要:
""" 创建ndarray数组(zeros,ones,full,*_like,eye,identity) """ import numpy as np print("zeros:", np.zeros([1, 3])) print("ones:", np.ones([1, 3])) print("full:", np.full([1, 3], 7)) print("ones_like", np.o 阅读全文
摘要:
import numpy as np a = np.array([[1, 1, 1, 2, 2, 2]]) a1 = np.array(a) a2 = np.asarray(a) a3 = np.copy(a) print("a1:", a1) print("a2:", a2) print("a3:", a3) a1: [[1 1 1 2 2 2]] a2: [[1 1 1 2 2 2]] a3: 阅读全文