mxnet.ndarray.ones¶
-
mxnet.ndarray.
ones
(shape, ctx=None, dtype=None, **kwargs)[source]¶ Returns a new array filled with all ones, with the given shape and type.
- Parameters
shape (int or tuple of int or list of int) – The shape of the empty array.
ctx (Context, optional) – An optional device context. Defaults to the current default context (
mxnet.context.current_context()
).dtype (str or numpy.dtype, optional) – An optional value type (default is float32).
out (NDArray, optional) – The output NDArray (default is None).
- Returns
A new array of the specified shape filled with all ones.
- Return type
Examples
>>> mx.nd.ones(1).asnumpy() array([ 1.], dtype=float32) >>> mx.nd.ones((1,2), mx.gpu(0)) <NDArray 1x2 @gpu(0)> >>> mx.nd.ones((1,2), dtype='float16').asnumpy() array([[ 1., 1.]], dtype=float16)