mxnet基础到提高(48)-ones和ones_like
生活随笔
收集整理的這篇文章主要介紹了
mxnet基础到提高(48)-ones和ones_like
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
返回全1元素矩陣
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 NDArray from mxnet import nd import mxnet as mx a = mx.nd.ones(12) print(a) b = mx.nd.ones((3,4)) print(b) c=mx.nd.ones((2,8), dtype='float16').asnumpy() print(c) [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] <NDArray 12 @cpu(0)>[[1. 1. 1. 1.][1. 1. 1. 1.][1. 1. 1. 1.]] <NDArray 3x4 @cpu(0)> [[1. 1. 1. 1. 1. 1. 1. 1.][1. 1. 1. 1. 1. 1. 1. 1.]]返回相同形狀的全1元素矩陣
mxnet.ndarray.ones_like(data=None, out=None, name=None, **kwargs) Return an array of ones with the same shape and type as the input array.Parameters data (NDArray) – The inputout (NDArray, optional) – The output NDArray to hold the result.Returns out – The output of this function.Return type NDArray or list of NDArrays [[1. 2. 3.][4. 5. 6.]] <NDArray 2x3 @cpu(0)>[[1. 1. 1.][1. 1. 1.]] <NDArray 2x3 @cpu(0)> from mxnet import nd import mxnet as mx a = mx.nd.array(((1,2,3),(4,5,6))) print(a) b=mx.nd.ones_like(a) print(b)總結
以上是生活随笔為你收集整理的mxnet基础到提高(48)-ones和ones_like的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python3精要(64)-Python
- 下一篇: 线性规划之单纯形法(2)