1. 程式人生 > >numpy模塊的簡單介紹

numpy模塊的簡單介紹

pri style clas 模塊 port zeros nbsp ray import

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

numpy模塊的簡單介紹