numpy模块的简单介绍
import numpy as np ret = np.arange(3) print(ret) """ 运行结果 [0 1 2] """
import numpy as np
ret = np.array([1,2,3,4])
print(ret)
"""
运行结果
[1 2 3 4]
"""
import numpy as np
ret = np.ones(5)
print(ret)
ret2 = np.zeros(7)
print(ret2)
ret3 = ret.astype(np.int32)
print(ret3)
"""
运行结果
[1. 1. 1. 1. 1.]
[0. 0. 0. 0. 0. 0. 0.]
[1 1 1 1 1]
"""
import numpy as np
ret = np.array([1,2,3,4],dtype=np.float32)
print(ret)
ret2 = ret.astype(np.int32)
print(ret2)
"""
运行结果
[1. 2. 3. 4.]
[1 2 3 4]
"""