mxnet.ndarray.arange¶

mxnet.ndarray.arange(start, stop=None, step=1.0, repeat=1, infer_range=False, ctx=None, dtype=<class 'numpy.float32'>)[source]

Returns evenly spaced values within a given interval.

Values are generated within the half-open interval [start, stop). In other words, the interval includes start but excludes stop. The function is similar to the built-in Python function range and to numpy.arange, but returns an NDArray.

Parameters
• start (number, optional) – Start of interval. The default start value is 0.

• stop (number) – End of interval.

• step (number, optional) – Spacing between values. The default step size is 1.

• repeat (int, optional) – Number of times to repeat each element. The default repeat count is 1.

• infer_range (boolean, optional) – When set to True, infer the stop position from the start, step, repeat, and output tensor size.

• ctx (Context, optional) – Device context. Default context is the current default context.

• dtype (str or numpy.dtype, optional) – The data type of the NDArray. The default datatype is np.float32.

Returns

NDArray of evenly spaced values in the specified range.

Return type

NDArray

Examples

>>> mx.nd.arange(3).asnumpy()
array([ 0.,  1.,  2.], dtype=float32)
>>> mx.nd.arange(2, 6).asnumpy()
array([ 2.,  3.,  4.,  5.], dtype=float32)
>>> mx.nd.arange(2, 6, step=2).asnumpy()
array([ 2.,  4.], dtype=float32)
>>> mx.nd.arange(2, 6, step=1.5, repeat=2).asnumpy()
array([ 2. ,  2. ,  3.5,  3.5,  5. ,  5. ], dtype=float32)
>>> mx.nd.arange(2, 6, step=2, repeat=3, dtype='int32').asnumpy()
array([2, 2, 2, 4, 4, 4], dtype=int32)