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

 

posted @ 2018-12-06 07:20  疯狂的骆驼  阅读(252)  评论(0编辑  收藏  举报