數列生成
>>> np.zeros(5)
#array([ 0., 0., 0., 0., 0.])
>>> np.ones(5)
#array([ 1., 1., 1., 1., 1.])
>>> np.arange(5)
#array([0, 1, 2, 3, 4])
數列變形
>>> np.arange(12)
#array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
>>> np.arange(12).reshape(2,6)
#array([[ 0, 1, 2, 3, 4, 5],
# [ 6, 7, 8, 9, 10, 11]])
>>> np.arange(12).reshape(3,4)
#array([[ 0, 1, 2, 3],
# [ 4, 5, 6, 7],
# [ 8, 9, 10, 11]])
>>> np.arange(12).reshape(4,3)
#array([[ 0, 1, 2],
# [ 3, 4, 5],
# [ 6, 7, 8],
# [ 9, 10, 11]])
>>> np.arange(12).reshape(6,2)
#array([[ 0, 1],
# [ 2, 3],
# [ 4, 5],
# [ 6, 7],
# [ 8, 9],
# [10, 11]])
>>> np.arange(12).reshape(12,1).flatten()
#array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
查看數列形狀
>>> np.arange(12).reshape(1,2,3,2)
#array([[[[ 0, 1],
# [ 2, 3],
# [ 4, 5]],
#
# [[ 6, 7],
# [ 8, 9],
# [10, 11]]]])
>>> np.arange(12).reshape(1,2,3,2).shape
#(1, 2, 3, 2)