demo.py(numpy,创建数组):
# coding=utf-8
import numpy as np
# 使用numpy生成数组,得到ndarray的类型
t1 = np.array([1,2,3])
print(t1) # [1 2 3]
print(type(t1)) # <class 'numpy.ndarray'>
t2 = np.array(range(10))
print(t2) # [0 1 2 3 4 5 6 7 8 9]
print(type(t2)) # <class 'numpy.ndarray'>
t3 = np.arange(4,10,2) # 2表示步长,可以省略
print(t3) # [4 6 8]
print(type(t3)) # <class 'numpy.ndarray'>
demo.py(dtype,numpy中的数据类型):
# coding=utf-8
import numpy as np
import random
# numpy中的数据类型
t1 = np.arange(10)
# dtype表示存放的数据类型
print(t1.dtype) # int64 (64位电脑默认是int64)
t2 = np.array(range(1,4),dtype="float32") # dtype参数指定numpy中的数据类型
# t2 = np.array(range(1,4),dtype="i1")
print(t2) # [