nlcpy.ones

nlcpy.ones(shape, dtype=None, order='C')[ソース]

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

Parameters
shapeint or sequence of ints

Shape of the new array, e.g., (2, 3) or 2.

dtypedtype, optional

The desired dtype for the array, e.g, nlcpy.int64. Default is nlcpy.float64.

order{'C', 'F'}, optional

Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.

Returns
outndarray

Array of ones with the given shape, dtype, and order.

参考

ones_like

Returns an array of ones with the same shape and type as a given array.

empty

Returns a new array of given shape and type, without initializing entries.

zeros

Returns a new array of given shape and type, filled with zeros.

full

Returns a new array of given shape and type, filled with fill_value.

Examples

>>> import nlcpy as vp
>>> vp.ones(5)
array([1., 1., 1., 1., 1.])
>>> vp.ones((5,), dtype=int)
array([1, 1, 1, 1, 1])
>>> vp.ones((2, 1))
array([[1.],
       [1.]])
>>> s = (2,2)
>>> vp.ones(s)
array([[1., 1.],
       [1., 1.]])