Fork me on GitHub

  ones是numpy的一个内置函数,作用是生成参数为一的数组。英文解释:

Return a new array of given shape and type, filled with ones.

例子:

>>> np.ones(5)
array([ 1.,  1.,  1.,  1.,  1.])
>>> np.ones((5,), dtype=np.int)
array([1, 1, 1, 1, 1])
>>> np.ones((2, 1))
array([[ 1.],
       [ 1.]])
>>> s = (2,2)
>>> np.ones(s)
array([[ 1.,  1.],
       [ 1.,  1.]])

 

posted on 2017-12-14 14:00  虚生  阅读(2361)  评论(0编辑  收藏  举报