# NDArray API¶

NDArray 程序包 (mxnet.ndarray) 包含类似于 numpy.ndarray 的 张量计算包. 它的语法很相近, 除了增加了一些处理 I/O 和多设备的调用.

## Create NDArray¶

>>> import mxnet as mx
>>> # all-zero array of dimension 100x50
>>> a = mx.nd.zeros((100, 50))
>>> # all-one array of dimension 256x32x128x1
>>> b = mx.nd.ones((256, 32, 128, 1))
>>> # initialize array with contents
>>> c = mx.nd.array([[1, 2, 3], [4, 5, 6]])


## NDArray operations¶

### 算术操作¶

>>> import mxnet as mx
>>> a = mx.nd.zeros((100, 50))
>>> a.shape
(100L, 50L)
>>> b = mx.nd.ones((100, 50))
>>> # c and d will be calculated in parallel here!
>>> c = a + b
>>> d = a - b
>>> # inplace operation, b's contents will be modified, but c and d won't be affected.
>>> b += d


### 切片操作¶

>>> import mxnet as mx
>>> a = mx.nd.zeros((100, 50))
>>> a[0:10] = 1   # first 10 rows will become 1


## Conversion from/to numpy.ndarray¶

MXNet NDArray 提供了很自然的方式来支持mxnet.ndarraynumpy.ndarray 之间的互相转换:

>>> import mxnet as mx
>>> import numpy as np
>>> a = np.array([1,2,3])
>>> b = mx.nd.array(a)                  # convert from numpy array
>>> b
<mxnet.ndarray.NDArray object at ...>
>>> b.asnumpy()                         # convert to numpy array
array([ 1., 2., 3.], dtype=float32)


>>> import mxnet as mx
>>> a = mx.nd.zeros((100, 200))
>>> b = mx.nd.zeros((100, 200))
>>> # save list of NDArrays
>>> mx.nd.save("/path/to/array/file", [a, b])
>>> # save dictionary of NDArrays to AWS S3
>>> mx.nd.save("s3://path/to/s3/array", {'A' : a, 'B' : b})
>>> # save list of NDArrays to hdfs.
>>> mx.nd.save("hdfs://path/to/hdfs/array", [a, b])


• 你可以在所有的 mxnet 的其他编程语言的绑定中相同的接口.
• 已经支持 S3 和 HDFS

## Multi-device Support¶

>>> import mxnet as mx
>>> cpu_a = mx.nd.zeros((100, 200))
>>> cpu_a.context
cpu(0)
>>> with mx.Context(mx.gpu(0)):
>>>   gpu_a = mx.nd.ones((100, 200))
>>> gpu_a.context
gpu(0)
>>> ctx = mx.Context(mx.gpu(0))
>>> gpu_b = mx.nd.zeros((100, 200), ctx)
>>> gpu_b.context
gpu(0)


>>> import mxnet as mx
>>> x = mx.nd.zeros((100, 200))
>>> with mx.Context(mx.gpu(0)):
>>>   y = mx.nd.zeros((100, 200))
>>> z = x + y
mxnet.base.MXNetError: [13:29:12] src/ndarray/ndarray.cc:33: Check failed: lhs.ctx() == rhs.ctx() operands context mismatch
>>> cpu_y = mx.nd.zeros((100, 200))
>>> y.copyto(cpu_y)
>>> z = x + cpu_y


## NDArray API Reference¶

NDArray API of mxnet.

mxnet.ndarray.waitall()

Wait all async operation to finish in MXNet

This function is used for benchmark only

class mxnet.ndarray.NDArray(handle, writable=True)

NDArray object in mxnet.

NDArray is basic ndarray/Tensor like data structure in mxnet.

reshape(new_shape)

Return a reshaped NDArray that shares memory with current one.

Parameters: new_shape (iterable of int) – new shape of NDArray
broadcast_to(shape)

Broadcasting the current NDArray into the given shape. The semantics is the same with numpy‘s broadcasting

wait_to_read()

Block until all pending writes operations on current NDArray are finished.

This function will return when all the pending writes to the current NDArray finishes. There can still be pending read going on when the function returns.

shape

Get shape of current NDArray.

Returns: a tuple representing shape of current ndarray
size

Get size of current NDArray.

Returns: an int representing size of current ndarray
context

Get context of current NDArray.

Returns: context – The context of current NDArray. mxnet.Context
dtype

Get data type of current NDArray.

Returns: an numpy.dtype object representing type of current ndarray
T

Get transpose of current NDArray

asnumpy()

Return a copied numpy array of current array.

Returns: array – A copy of array content. numpy.ndarray
asscalar()

Return a CPU scalar(float) of current ndarray.

This ndarray must have shape (1,)

Returns: scalar – The scalar representation of the ndarray. np.float
astype(dtype)

Return a copied numpy array of current array with specified type.

Parameters: dtype (str or numpy.dtype) – Desired type of result array. array – A copy of array content. numpy.ndarray
copyto(other)

Copy the content of current array to other.

When other is NDArray, the content is copied over. When other is a Context, a new NDArray in the context will be created as target

Parameters: other (NDArray or Context) – Target NDArray or context we want to copy data to. dst – The copy target NDArray NDArray
copy()

Make a copy of the current ndarray on the same context

Returns: cpy – The copy NDArray
as_in_context(context)

Return an NDArray that lives in the target context. If the array is already in that context, self is returned. Otherwise, a copy is made.

Parameters: context (Context) – The target context we want the return value to live in. A copy or self as an NDArray that lives in the target context.
mxnet.ndarray.onehot_encode(indices, out)

One hot encoding indices into matrix out.

Parameters: indices (NDArray) – An NDArray containing indices of the categorical features. out (NDArray) – The result holder of the encoding. out – Same as out. Array
mxnet.ndarray.empty(shape, ctx=None, dtype=None)

Create an empty uninitialized new NDArray, with specified shape.

Parameters: shape (tuple) – shape of the NDArray. ctx (Context, optional) – The context of the NDArray, default to current default context. dtype (str or numpy.dtype, optional) – The value type of the NDArray, default to np.float32 out – The created NDArray. Array
mxnet.ndarray.add(lhs, rhs)

Parameters: lhs (Array or float value) – left hand side operand rhs (Array of float value) – right hand side operand out – result array Array
mxnet.ndarray.subtract(lhs, rhs)

Perform element-wise subtract

Parameters: lhs (Array or float value) – left hand side operand rhs (Array of float value) – right hand side operand out – result array Array
mxnet.ndarray.multiply(lhs, rhs)

Perform element-wise multiplication

Parameters: lhs (Array or float value) – left hand side operand rhs (Array of float value) – right hand side operand out – result array Array
mxnet.ndarray.divide(lhs, rhs)

Perform element-wise divide

Parameters: lhs (Array or float value) – left hand side operand rhs (Array of float value) – right hand side operand out – result array Array
mxnet.ndarray.power(lhs, rhs)

Perform power operator

Parameters: lhs (Array or float value) – left hand side operand rhs (Array of float value) – right hand side operand out – result array Array
mxnet.ndarray.maximum(lhs, rhs)

Perform maximum operator

Parameters: lhs (Array or float value) – left hand side operand rhs (Array of float value) – right hand side operand out – result array Array
mxnet.ndarray.minimum(lhs, rhs)

Perform minimum operator

Parameters: lhs (Array or float value) – left hand side operand rhs (Array of float value) – right hand side operand out – result array Array
mxnet.ndarray.equal(lhs, rhs)

Return (lhs == rhs) element-wise.

Parameters: lhs (Array or float value) – left hand side operand rhs (Array of float value) – right hand side operand out – result array Array
mxnet.ndarray.not_equal(lhs, rhs)

Return (lhs != rhs) element-wise.

Parameters: lhs (Array or float value) – left hand side operand rhs (Array of float value) – right hand side operand out – result array Array
mxnet.ndarray.greater(lhs, rhs)

Return (lhs > rhs) element-wise.

Parameters: lhs (Array or float value) – left hand side operand rhs (Array of float value) – right hand side operand out – result array Array
mxnet.ndarray.greater_equal(lhs, rhs)

Return (lhs >= rhs) element-wise.

Parameters: lhs (Array or float value) – left hand side operand rhs (Array of float value) – right hand side operand out – result array Array
mxnet.ndarray.lesser(lhs, rhs)

Return (lhs < rhs) element-wise.

Parameters: lhs (Array or float value) – left hand side operand rhs (Array of float value) – right hand side operand out – result array Array
mxnet.ndarray.lesser_equal(lhs, rhs)

Return (lhs <= rhs) element-wise.

Parameters: lhs (Array or float value) – left hand side operand rhs (Array of float value) – right hand side operand out – result array Array
mxnet.ndarray.true_divide(lhs, rhs)

Same as numpy’s true_divide. It adjusts the output type to present the best answer, regardless of input types.

mxnet.ndarray.negative(arr)

Return the negation of array values

mxnet.ndarray.zeros(shape, ctx=None, dtype=None)

Create a new NDArray filled with 0, with specified shape.

Parameters: shape (tuple) – shape of the NDArray. ctx (Context, optional.) – The context of the NDArray, default to current default context. dtype (str or numpy.dtype, optional) – The value type of the NDArray, default to np.float32 out – The created NDArray. Array
mxnet.ndarray.ones(shape, ctx=None, dtype=None)

Create a new NDArray filled with 1, with specified shape.

Parameters: shape (tuple) – shape of the NDArray. ctx (Context, optional) – The context of the NDArray, default to current default context. dtype (str or numpy.dtype, optional) – The value type of the NDArray, default to np.float32 out – The created NDArray. Array
mxnet.ndarray.full(shape, val, ctx=None, dtype=None)

Create a new NDArray filled with given value, with specified shape.

Parameters: shape (tuple) – shape of the NDArray. val (float or int) – value to be filled with. ctx (Context, optional) – The context of the NDArray, default to current default context. dtype (str or numpy.dtype, optional) – The value type of the NDArray, default to np.float32 out – The created NDArray. Array
mxnet.ndarray.array(source_array, ctx=None, dtype=None)

Create a new NDArray that copies content from source_array.

Parameters: source_array (array_like) – Source data to create NDArray from. ctx (Context, optional) – The context of the NDArray, default to current default context. dtype (str or numpy.dtype, optional) – The value type of the NDArray, default to np.float32 out – The created NDArray. Array
mxnet.ndarray.concatenate(arrays, axis=0, always_copy=True)

Concatenate a list of NDArrays along the first dimension.

Parameters: arrays (list of NDArray) – Arrays to be concatenate. They must have identical shape except the first dimension. They also must have the same data type. axis (int) – The axis along which to concatenate. always_copy (bool) – Default True. When not True, if the arrays only contain one NDArray, that element will be returned directly, avoid copying. An NDArray that lives on the same context as arrays[0].context.
mxnet.ndarray.arange(start, stop=None, step=1.0, repeat=1, ctx=None, dtype=None)
Simlar function in the MXNet ndarray as numpy.arange
Parameters: start (number, optional) – Start of interval. The interval includes this value. The default start value is 0. stop (number, optional) – End of interval. The interval does not include this value. step (number, optional) – Spacing between values repeat (number, optional) – “The repeating time of all elements. E.g repeat=3, the element a will be repeated three times –> a, a, a. ctx (Context, optional) – The context of the NDArray, default to current default context. dtype (str or numpy.dtype, optional) – The value type of the NDArray, default to np.float32 out – The created NDArray NDArray
mxnet.ndarray.load(fname)

You can also use pickle to do the job if you only work on python. The advantage of load/save is the file is language agnostic. This means the file saved using save can be loaded by other language binding of mxnet. You also get the benefit being able to directly load/save from cloud storage(S3, HDFS)

Parameters: fname (str) – The name of the file.Can be S3 or HDFS address (remember built with S3 support). Example of fname: s3://my-bucket/path/my-s3-ndarray hdfs://my-bucket/path/my-hdfs-ndarray /path-to/my-local-ndarray out – List of NDArray or dict of str->NDArray, depending on what was saved. list of NDArray or dict of str to NDArray
mxnet.ndarray.save(fname, data)

Save list of NDArray or dict of str->NDArray to binary file.

You can also use pickle to do the job if you only work on python. The advantage of load/save is the file is language agnostic. This means the file saved using save can be loaded by other language binding of mxnet. You also get the benefit being able to directly load/save from cloud storage(S3, HDFS)

Parameters: fname (str) – The name of the file.Can be S3 or HDFS address (remember built with S3 support). Example of fname: s3://my-bucket/path/my-s3-ndarray hdfs://my-bucket/path/my-hdfs-ndarray /path-to/my-local-ndarray data (list of NDArray or dict of str to NDArray) – The data to be saved.
mxnet.ndarray.imdecode(str_img, clip_rect=(0, 0, 0, 0), out=None, index=0, channels=3, mean=None)

Decode an image from string. Requires OpenCV to work.

Parameters: str_img (str) – binary image data clip_rect (iterable of 4 int) – clip decoded image to rectangle (x0, y0, x1, y1) out (NDArray) – output buffer. can be 3 dimensional (c, h, w) or 4 dimensional (n, c, h, w) index (int) – output decoded image to i-th slice of 4 dimensional buffer channels (int) – number of channels to output. Decode to grey scale when channels = 1. mean (NDArray) – subtract mean from decode image before outputing.
mxnet.ndarray.Activation(*args, **kwargs)

Elementwise activation function.

The following activation types are supported (operations are applied elementwisely to each scalar of the input tensor):

• relu: Rectified Linear Unit, y = max(x, 0)
• sigmoid: y = 1 / (1 + exp(-x))
• tanh: Hyperbolic tangent, y = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
• softrelu: Soft ReLU, or SoftPlus, y = log(1 + exp(x))

See LeakyReLU for other activations with parameters.

Parameters: data (Symbol) – Input data to activation function. act_type ({'relu', 'sigmoid', 'softrelu', 'tanh'}, required) – Activation function to be applied. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.BatchNorm(*args, **kwargs)

Apply batch normalization to input.

Parameters: data (Symbol) – Input data to batch normalization gamma (Symbol) – gamma matrix beta (Symbol) – beta matrix eps (float, optional, default=0.001) – Epsilon to prevent div 0 momentum (float, optional, default=0.9) – Momentum for moving average fix_gamma (boolean, optional, default=True) – Fix gamma while training use_global_stats (boolean, optional, default=False) – Whether use global moving statistics instead of local batch-norm. This will force change batch-norm into a scale shift operator. output_mean_var (boolean, optional, default=False) – Output All,normal mean and var out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.BilinearSampler(*args, **kwargs)
Apply bilinear sampling to input feature map, which is the key of “[NIPS2015] Spatial Transformer Networks”
output[batch, channel, y_dst, x_dst] = G(data[batch, channel, y_src, x_src) x_dst, y_dst enumerate all spatial locations in output x_src = grid[batch, 0, y_dst, x_dst] y_src = grid[batch, 1, y_dst, x_dst] G() denotes the bilinear interpolation kernel

The out-boundary points will be padded as zeros. (The boundary is defined to be [-1, 1]) The shape of output will be (data.shape[0], data.shape[1], grid.shape[2], grid.shape[3]) The operator assumes that grid has been nomalized. If you want to design a CustomOp to manipulate grid, please refer to GridGeneratorOp.

Parameters: data (Symbol) – Input data to the BilinearsamplerOp. grid (Symbol) – Input grid to the BilinearsamplerOp.grid has two channels: x_src, y_src out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.BlockGrad(*args, **kwargs)

Get output from a symbol and pass 0 gradient back

From:src/operator/tensor/elemwise_unary_op.cc:31

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.Cast(*args, **kwargs)

Convert data type to dtype

From:src/operator/tensor/elemwise_unary_op.cc:58

Parameters: data (NDArray) – Source input dtype ({'float16', 'float32', 'float64', 'int32', 'uint8'}, required) – Output data type. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.Concat(*args, **kwargs)

Perform a feature concat on channel dim (defaut is 1) over all This function support variable length of positional input.

Parameters: data (Symbol[]) – List of tensors to concatenate num_args (int, required) – Number of inputs to be concated. dim (int, optional, default='1') – the dimension to be concated. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.Convolution(*args, **kwargs)

Apply convolution to input then add a bias.

Parameters: data (Symbol) – Input data to the ConvolutionOp. weight (Symbol) – Weight matrix. bias (Symbol) – Bias parameter. kernel (Shape(tuple), required) – convolution kernel size: (h, w) or (d, h, w) stride (Shape(tuple), optional, default=()) – convolution stride: (h, w) or (d, h, w) dilate (Shape(tuple), optional, default=()) – convolution dilate: (h, w) or (d, h, w) pad (Shape(tuple), optional, default=()) – pad for convolution: (h, w) or (d, h, w) num_filter (int (non-negative), required) – convolution filter(channel) number num_group (int (non-negative), optional, default=1) – Number of group partitions. Equivalent to slicing input into num_group partitions, apply convolution on each, then concatenate the results workspace (long (non-negative), optional, default=1024) – Maximum tmp workspace allowed for convolution (MB). no_bias (boolean, optional, default=False) – Whether to disable bias parameter. cudnn_tune ({None, 'fastest', 'limited_workspace', 'off'},optional, default='None') – Whether to pick convolution algo by running performance test. Leads to higher startup time but may give faster speed. Options are: ‘off’: no tuning ‘limited_workspace’: run test and pick the fastest algorithm that doesn’t exceed workspace limit. ‘fastest’: pick the fastest algorithm and ignore workspace limit. If set to None (default), behavior is determined by environment variable MXNET_CUDNN_AUTOTUNE_DEFAULT: 0 for off, 1 for limited workspace (default), 2 for fastest. cudnn_off (boolean, optional, default=False) – Turn off cudnn for this layer. layout ({None, 'NCDHW', 'NCHW', 'NDHWC', 'NHWC'},optional, default='None') – Set layout for input, output and weight. Empty for default layout: NCHW for 2d and NCDHW for 3d. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.Correlation(*args, **kwargs)

Apply correlation to inputs

Parameters: data1 (Symbol) – Input data1 to the correlation. data2 (Symbol) – Input data2 to the correlation. kernel_size (int (non-negative), optional, default=1) – kernel size for Correlation must be an odd number max_displacement (int (non-negative), optional, default=1) – Max displacement of Correlation stride1 (int (non-negative), optional, default=1) – stride1 quantize data1 globally stride2 (int (non-negative), optional, default=1) – stride2 quantize data2 within the neighborhood centered around data1 pad_size (int (non-negative), optional, default=0) – pad for Correlation is_multiply (boolean, optional, default=True) – operation type is either multiplication or subduction out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.Crop(*args, **kwargs)

Crop the 2nd and 3rd dim of input data, with the corresponding size of h_w or with width and height of the second input symbol, i.e., with one input, we need h_w to specify the crop height and width, otherwise the second input symbol’s size will be used This function support variable length of positional input.

Parameters: data (Symbol or Symbol[]) – Tensor or List of Tensors, the second input will be used as crop_like shape reference num_args (int, required) – Number of inputs for crop, if equals one, then we will use the h_wfor crop height and width, else if equals two, then we will use the heightand width of the second input symbol, we name crop_like here offset (Shape(tuple), optional, default=(0,0)) – crop offset coordinate: (y, x) h_w (Shape(tuple), optional, default=(0,0)) – crop height and weight: (h, w) center_crop (boolean, optional, default=False) – If set to true, then it will use be the center_crop,or it will crop using the shape of crop_like out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.Custom(*args, **kwargs)

Custom operator implemented in frontend.

Parameters: op_type (string) – Type of custom operator. Must be registered first. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.Deconvolution(*args, **kwargs)

Apply deconvolution to input then add a bias.

Parameters: data (Symbol) – Input data to the DeconvolutionOp. weight (Symbol) – Weight matrix. bias (Symbol) – Bias parameter. kernel (Shape(tuple), required) – deconvolution kernel size: (y, x) stride (Shape(tuple), optional, default=(1,1)) – deconvolution stride: (y, x) pad (Shape(tuple), optional, default=(0,0)) – pad for deconvolution: (y, x), a good number is : (kernel-1)/2, if target_shape set, pad will be ignored and will be computed automatically adj (Shape(tuple), optional, default=(0,0)) – adjustment for output shape: (y, x), if target_shape set, adj will be ignored and will be computed automatically target_shape (Shape(tuple), optional, default=(0,0)) – output shape with targe shape : (y, x) num_filter (int (non-negative), required) – deconvolution filter(channel) number num_group (int (non-negative), optional, default=1) – number of groups partition workspace (long (non-negative), optional, default=512) – Tmp workspace for deconvolution (MB) no_bias (boolean, optional, default=True) – Whether to disable bias parameter. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.Dropout(*args, **kwargs)

Apply dropout to input. During training, each element of the input is randomly set to zero with probability p. And then the whole tensor is rescaled by 1/(1-p) to keep the expectation the same as before applying dropout. During the test time, this behaves as an identity map.

Parameters: data (Symbol) – Input data to dropout. p (float, optional, default=0.5) – Fraction of the input that gets dropped out at training time out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.ElementWiseSum(*args, **kwargs)

Perform element sum of inputs

From:src/operator/tensor/elemwise_sum.cc:56 This function support variable length of positional input.

Parameters: args (NDArray[]) – List of input tensors out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.Embedding(*args, **kwargs)

Map integer index to vector representations (embeddings). Those embeddings are learnable parameters. For a input of shape (d1, ..., dK), the output shape is (d1, ..., dK, output_dim). All the input values should be integers in the range [0, input_dim).

From:src/operator/tensor/indexing_op.cc:19

Parameters: data (Symbol) – Input data to the EmbeddingOp. weight (Symbol) – Embedding weight matrix. input_dim (int, required) – vocabulary size of the input indices. output_dim (int, required) – dimension of the embedding vectors. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.Flatten(*args, **kwargs)

Flatten input into 2D by collapsing all the higher dimensions. A (d1, d2, ..., dK) tensor is flatten to (d1, d2* ... *dK) matrix.

Parameters: data (NDArray) – Input data to reshape. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.FullyConnected(*args, **kwargs)

Apply matrix multiplication to input then add a bias. It maps the input of shape (batch_size, input_dim) to the shape of (batch_size, num_hidden). Learnable parameters include the weights of the linear transform and an optional bias vector.

Parameters: data (Symbol) – Input data to the FullyConnectedOp. weight (Symbol) – Weight matrix. bias (Symbol) – Bias parameter. num_hidden (int, required) – Number of hidden nodes of the output. no_bias (boolean, optional, default=False) – Whether to disable bias parameter. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.GridGenerator(*args, **kwargs)

generate sampling grid for bilinear sampling.

Parameters: data (Symbol) – Input data to the GridGeneratorOp. transform_type ({'affine', 'warp'}, required) – transformation type if transformation type is affine, data is affine matrix : (batch, 6) if transformation type is warp, data is optical flow : (batch, 2, h, w) target_shape (Shape(tuple), optional, default=(0,0)) – if transformation type is affine, the operator need a target_shape : (H, W) if transofrmation type is warp, the operator will ignore target_shape out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.IdentityAttachKLSparseReg(*args, **kwargs)

Apply a sparse regularization to the output a sigmoid activation function.

Parameters: data (Symbol) – Input data. sparseness_target (float, optional, default=0.1) – The sparseness target penalty (float, optional, default=0.001) – The tradeoff parameter for the sparseness penalty momentum (float, optional, default=0.9) – The momentum for running average out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.InstanceNorm(*args, **kwargs)

An operator taking in a n-dimensional input tensor (n > 2), and normalizing the input by subtracting the mean and variance calculated over the spatial dimensions. This is an implemention of the operator described in “Instance Normalization: The Missing Ingredient for Fast Stylization”, D. Ulyanov, A. Vedaldi, V. Lempitsky, 2016 (arXiv:1607.08022v2). This layer is similar to batch normalization, with two differences: first, the normalization is carried out per example (‘instance’), not over a batch. Second, the same normalization is applied both at test and train time. This operation is also known as ‘contrast normalization’.

Parameters: data (Symbol) – A n-dimensional tensor (n > 2) of the form [batch, channel, spatial_dim1, spatial_dim2, ...]. gamma (Symbol) – A vector of length ‘channel’, which multiplies the normalized input. beta (Symbol) – A vector of length ‘channel’, which is added to the product of the normalized input and the weight. eps (float, optional, default=0.001) – Epsilon to prevent division by 0. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.L2Normalization(*args, **kwargs)

Set the l2 norm of each instance to a constant.

Parameters: data (Symbol) – Input data to the L2NormalizationOp. eps (float, optional, default=1e-10) – Epsilon to prevent div 0 mode ({'channel', 'instance', 'spatial'},optional, default='instance') – Normalization Mode. If set to instance, this operator will compute a norm for each instance in the batch; this is the default mode. If set to channel, this operator will compute a cross channel norm at each position of each instance. If set to spatial, this operator will compute a norm for each channel. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.LRN(*args, **kwargs)

Apply convolution to input then add a bias.

Parameters: data (Symbol) – Input data to the ConvolutionOp. alpha (float, optional, default=0.0001) – value of the alpha variance scaling parameter in the normalization formula beta (float, optional, default=0.75) – value of the beta power parameter in the normalization formula knorm (float, optional, default=2) – value of the k parameter in normalization formula nsize (int (non-negative), required) – normalization window width in elements. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.LeakyReLU(*args, **kwargs)

Apply activation function to input.

Parameters: data (Symbol) – Input data to activation function. act_type ({'elu', 'leaky', 'prelu', 'rrelu'},optional, default='leaky') – Activation function to be applied. slope (float, optional, default=0.25) – Init slope for the activation. (For leaky and elu only) lower_bound (float, optional, default=0.125) – Lower bound of random slope. (For rrelu only) upper_bound (float, optional, default=0.334) – Upper bound of random slope. (For rrelu only) out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.LinearRegressionOutput(*args, **kwargs)

Use linear regression for final output, this is used on final output of a net.

Parameters: data (Symbol) – Input data to function. label (Symbol) – Input label to function. grad_scale (float, optional, default=1) – Scale the gradient by a float factor out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.LogisticRegressionOutput(*args, **kwargs)

Use Logistic regression for final output, this is used on final output of a net. Logistic regression is suitable for binary classification or probability prediction tasks.

Parameters: data (Symbol) – Input data to function. label (Symbol) – Input label to function. grad_scale (float, optional, default=1) – Scale the gradient by a float factor out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.MAERegressionOutput(*args, **kwargs)

Use mean absolute error regression for final output, this is used on final output of a net.

Parameters: data (Symbol) – Input data to function. label (Symbol) – Input label to function. grad_scale (float, optional, default=1) – Scale the gradient by a float factor out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.MakeLoss(*args, **kwargs)

Get output from a symbol and pass 1 gradient back. This is used as a terminal loss if unary and binary operator are used to composite a loss with no declaration of backward dependency

Parameters: data (Symbol) – Input data. grad_scale (float, optional, default=1) – gradient scale as a supplement to unary and binary operators valid_thresh (float, optional, default=0) – regard element valid when x > valid_thresh, this is used only in valid normalization mode. normalization ({'batch', 'null', 'valid'},optional, default='null') – If set to null, op will not normalize on output gradient.If set to batch, op will normalize gradient by divide batch size.If set to valid, op will normalize gradient by divide # sample marked as valid out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.Pad(*args, **kwargs)

Pads an n-dimensional input tensor. Allows for precise control of the padding type and how much padding to apply on both sides of a given dimension.

Parameters: data (Symbol) – An n-dimensional input tensor. mode ({'constant', 'edge'}, required) – Padding type to use. “constant” pads all values with a constant value, the value of which can be specified with the constant_value option. “edge” uses the boundary values of the array as padding. pad_width (Shape(tuple), required) – A tuple of padding widths of length 2*r, where r is the rank of the input tensor, specifying number of values padded to the edges of each axis. (before_1, after_1, ... , before_N, after_N) unique pad widths for each axis. Equivalent to pad_width in numpy.pad, but flattened. constant_value (double, optional, default=0) – This option is only used when mode is “constant”. This value will be used as the padding value. Defaults to 0 if not specified. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.Pooling(*args, **kwargs)

Perform spatial pooling on inputs.

Parameters: data (Symbol) – Input data to the pooling operator. global_pool (boolean, optional, default=False) – Ignore kernel size, do global pooling based on current input feature map. This is useful for input with different shape kernel (Shape(tuple), required) – pooling kernel size: (y, x) or (d, y, x) pool_type ({'avg', 'max', 'sum'}, required) – Pooling type to be applied. pooling_convention ({'full', 'valid'},optional, default='valid') – Pooling convention to be applied.kValid is default setting of Mxnet and rounds down the output pooling size.kFull is compatible with Caffe and rounds up the output pooling size. stride (Shape(tuple), optional, default=(1,1)) – stride: for pooling (y, x) or (d, y, x) pad (Shape(tuple), optional, default=(0,0)) – pad for pooling: (y, x) or (d, y, x) out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.RNN(*args, **kwargs)

Apply a recurrent layer to input.

Parameters: data (Symbol) – Input data to RNN parameters (Symbol) – Vector of all RNN trainable parameters concatenated state (Symbol) – initial hidden state of the RNN state_cell (Symbol) – initial cell state for LSTM networks (only for LSTM) state_size (int (non-negative), required) – size of the state for each layer num_layers (int (non-negative), required) – number of stacked layers bidirectional (boolean, optional, default=False) – whether to use bidirectional recurrent layers mode ({'gru', 'lstm', 'rnn_relu', 'rnn_tanh'}, required) – the type of RNN to compute p (float, optional, default=0) – Dropout probability, fraction of the input that gets dropped out at training time state_outputs (boolean, optional, default=False) – Whether to have the states as symbol outputs. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.ROIPooling(*args, **kwargs)

Performs region-of-interest pooling on inputs. Resize bounding box coordinates by spatial_scale and crop input feature maps accordingly. The cropped feature maps are pooled by max pooling to a fixed size output indicated by pooled_size. batch_size will change to the number of region bounding boxes after ROIPooling

Parameters: data (Symbol) – Input data to the pooling operator, a 4D Feature maps rois (Symbol) – Bounding box coordinates, a 2D array of [[batch_index, x1, y1, x2, y2]]. (x1, y1) and (x2, y2) are top left and down right corners of designated region of interest. batch_index indicates the index of corresponding image in the input data pooled_size (Shape(tuple), required) – fix pooled size: (h, w) spatial_scale (float, required) – Ratio of input feature map height (or w) to raw image height (or w). Equals the reciprocal of total stride in convolutional layers out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.Reshape(*args, **kwargs)

Reshape input according to a target shape spec. The target shape is a tuple and can be a simple list of dimensions such as (12,3) or it can incorporate special codes that correspond to contextual operations that refer to the input dimensions. The special codes are all expressed as integers less than 1. These codes effectively refer to a machine that pops input dims off the beginning of the input dims list and pushes resulting output dims onto the end of the output dims list, which starts empty. The codes are:

0 Copy Pop one input dim and push it onto the output dims
 -1 Infer Push a dim that is inferred later from all other output dims -2 CopyAll Pop all remaining input dims and push them onto output dims -3 Merge2 Pop two input dims, multiply them, and push result -4 Split2 Pop one input dim, and read two next target shape specs, push them both onto output dims (either can be -1 and will be inferred from the other

The exact mathematical behavior of these codes is given in the description of the ‘shape’ parameter. All non-codes (positive integers) just pop a dim off the input dims (if any), throw it away, and then push the specified integer onto the output dims.

Examples: Type Input Target Output Copy (2,3,4) (4,0,2) (4,3,2) Copy (2,3,4) (2,0,0) (2,3,4) Infer (2,3,4) (6,1,-1) (6,1,4) Infer (2,3,4) (3,-1,8) (3,1,8) CopyAll (9,8,7) (-2) (9,8,7) CopyAll (9,8,7) (9,-2) (9,8,7) CopyAll (9,8,7) (-2,1,1) (9,8,7,1,1) Merge2 (3,4) (-3) (12) Merge2 (3,4,5) (-3,0) (12,5) Merge2 (3,4,5) (0,-3) (3,20) Merge2 (3,4,5,6) (-3,0,0) (12,5,6) Merge2 (3,4,5,6) (-3,-2) (12,5,6) Split2 (12) (-4,6,2) (6,2) Split2 (12) (-4,2,6) (2,6) Split2 (12) (-4,-1,6) (2,6) Split2 (12,9) (-4,2,6,0) (2,6,9) Split2 (12,9,9,9) (-4,2,6,-2) (2,6,9,9,9) Split2 (12,12) (-4,2,-1,-4,-1,2) (2,6,6,2)

From:src/operator/tensor/matrix_op.cc:64

Parameters: data (NDArray) – Input data to reshape. target_shape (Shape(tuple), optional, default=(0,0)) – (Deprecated! Use shape instead.) Target new shape. One and only one dim can be 0, in which case it will be inferred from the rest of dims keep_highest (boolean, optional, default=False) – (Deprecated! Use shape instead.) Whether keep the highest dim unchanged.If set to true, then the first dim in target_shape is ignored,and always fixed as input shape (Shape(tuple), optional, default=()) – Target shape, a tuple, t=(t_1,t_2,..,t_m). the input dims be s=(s_1,s_2,.,s_n) (Let) – output dims u=(u_1,u_2,.,u_p) are computed from s and t. (The) – target shape tuple elements t_i are read in order, and used to generate successive output dims u_p (The) – t_i (meaning: behavior:) – explicit u_p = t_i (+ve) – copy u_p = s_i (0) – infer u_p = (Prod s_i) / (Prod u_j | j != p) (-1) – copy all u_p = s_i, u_p+1 = s_i+1, .. (-2) – merge two u_p = s_i * s_i+1 (-3) – split two u_p = a, u_p+1 = b | a * b = s_i (-4,a,b) – split directive (-4) in the target shape tuple is followed by two dimensions, one of which can be -1, which means it will be inferred from the other one and the original dimension. (The) – can only be one globally inferred dimension (-1), aside from any -1 occuring in a split directive. (The) – reverse (boolean, optional, default=False) – Whether to match the shapes from the backward. If reverse is true, 0 values in the shape argument will be searched from the backward. E.g the original shape is (10, 5, 4) and the shape argument is (-1, 0). If reverse is true, the new shape should be (50, 4). Otherwise it will be (40, 5). out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.SVMOutput(*args, **kwargs)

Support Vector Machine based transformation on input, backprop L2-SVM

Parameters: data (Symbol) – Input data to svm. label (Symbol) – Label data. margin (float, optional, default=1) – Scale the DType(param_.margin) for activation size regularization_coefficient (float, optional, default=1) – Scale the coefficient responsible for balacing coefficient size and error tradeoff use_linear (boolean, optional, default=False) – If set true, uses L1-SVM objective function. Default uses L2-SVM objective out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.SequenceLast(*args, **kwargs)

Takes the last element of a sequence. Takes an n-dimensional tensor of the form [max sequence length, batchsize, other dims] and returns a (n-1)-dimensional tensor of the form [batchsize, other dims]. This operator takes an optional input tensor sequence_length of positive ints of dimension [batchsize] when the sequence_length option is set to true. This allows the operator to handle variable-length sequences. If sequence_length is false, then each example in the batch is assumed to have the max sequence length.

Parameters: data (Symbol) – n-dimensional input tensor of the form [max sequence length, batchsize, other dims] sequence_length (Symbol) – vector of sequence lengths of size batchsize use_sequence_length (boolean, optional, default=False) – If set to true, this layer takes in extra input sequence_length to specify variable length sequence out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.SequenceMask(*args, **kwargs)

Sets all elements outside the sequence to a constant value. Takes an n-dimensional tensor of the form [max sequence length, batchsize, other dims] and returns a tensor of the same shape. This operator takes an optional input tensor sequence_length of positive ints of dimension [batchsize] when the sequence_length option is set to true. This allows the operator to handle variable-length sequences. If sequence_length is false, then each example in the batch is assumed to have the max sequence length, and this operator becomes the identity operator.

Parameters: data (Symbol) – n-dimensional input tensor of the form [max sequence length, batchsize, other dims] sequence_length (Symbol) – vector of sequence lengths of size batchsize use_sequence_length (boolean, optional, default=False) – If set to true, this layer takes in extra input sequence_length to specify variable length sequence value (float, optional, default=0) – The value to be used as a mask. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.SequenceReverse(*args, **kwargs)

Reverses the elements of each sequence. Takes an n-dimensional tensor of the form [max sequence length, batchsize, other dims] and returns a tensor of the same shape. This operator takes an optional input tensor sequence_length of positive ints of dimension [batchsize] when the sequence_length option is set to true. This allows the operator to handle variable-length sequences. If sequence_length is false, then each example in the batch is assumed to have the max sequence length.

Parameters: data (Symbol) – n-dimensional input tensor of the form [max sequence length, batchsize, other dims] sequence_length (Symbol) – vector of sequence lengths of size batchsize use_sequence_length (boolean, optional, default=False) – If set to true, this layer takes in extra input sequence_length to specify variable length sequence out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.SliceChannel(*args, **kwargs)

Slice input equally along specified axis

Parameters: num_outputs (int, required) – Number of outputs to be sliced. axis (int, optional, default='1') – Dimension along which to slice. squeeze_axis (boolean, optional, default=False) – If true AND the sliced dimension becomes 1, squeeze that dimension. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.Softmax(*args, **kwargs)

DEPRECATED: Perform a softmax transformation on input. Please use SoftmaxOutput

Parameters: data (Symbol) – Input data to softmax. grad_scale (float, optional, default=1) – Scale the gradient by a float factor ignore_label (float, optional, default=-1) – the label value will be ignored during backward (only works if use_ignore is set to be true). multi_output (boolean, optional, default=False) – If set to true, for a (n,k,x_1,..,x_n) dimensional input tensor, softmax will generate n*x_1*...*x_n output, each has k classes use_ignore (boolean, optional, default=False) – If set to true, the ignore_label value will not contribute to the backward gradient preserve_shape (boolean, optional, default=False) – If true, for a (n_1, n_2, ..., n_d, k) dimensional input tensor, softmax will generate (n1, n2, ..., n_d, k) output, normalizing the k classes as the last dimension. normalization ({'batch', 'null', 'valid'},optional, default='null') – If set to null, op will do nothing on output gradient.If set to batch, op will normalize gradient by divide batch sizeIf set to valid, op will normalize gradient by divide sample not ignored out_grad (boolean, optional, default=False) – Apply weighting from output gradient out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.SoftmaxActivation(*args, **kwargs)

Apply softmax activation to input. This is intended for internal layers. For output (loss layer) please use SoftmaxOutput. If mode=instance, this operator will compute a softmax for each instance in the batch; this is the default mode. If mode=channel, this operator will compute a num_channel-class softmax at each position of each instance; this can be used for fully convolutional network, image segmentation, etc.

Parameters: data (Symbol) – Input data to activation function. mode ({'channel', 'instance'},optional, default='instance') – Softmax Mode. If set to instance, this operator will compute a softmax for each instance in the batch; this is the default mode. If set to channel, this operator will compute a num_channel-class softmax at each position of each instance; this can be used for fully convolutional network, image segmentation, etc. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.SoftmaxOutput(*args, **kwargs)

Perform a softmax transformation on input, backprop with logloss.

Parameters: data (Symbol) – Input data to softmax. label (Symbol) – Label data, can also be probability value with same shape as data grad_scale (float, optional, default=1) – Scale the gradient by a float factor ignore_label (float, optional, default=-1) – the label value will be ignored during backward (only works if use_ignore is set to be true). multi_output (boolean, optional, default=False) – If set to true, for a (n,k,x_1,..,x_n) dimensional input tensor, softmax will generate n*x_1*...*x_n output, each has k classes use_ignore (boolean, optional, default=False) – If set to true, the ignore_label value will not contribute to the backward gradient preserve_shape (boolean, optional, default=False) – If true, for a (n_1, n_2, ..., n_d, k) dimensional input tensor, softmax will generate (n1, n2, ..., n_d, k) output, normalizing the k classes as the last dimension. normalization ({'batch', 'null', 'valid'},optional, default='null') – If set to null, op will do nothing on output gradient.If set to batch, op will normalize gradient by divide batch sizeIf set to valid, op will normalize gradient by divide sample not ignored out_grad (boolean, optional, default=False) – Apply weighting from output gradient out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.SpatialTransformer(*args, **kwargs)

Apply spatial transformer to input feature map.

Parameters: data (Symbol) – Input data to the SpatialTransformerOp. loc (Symbol) – localisation net, the output dim should be 6 when transform_type is affine. You shold initialize the weight and bias with identity tranform. target_shape (Shape(tuple), optional, default=(0,0)) – output shape(h, w) of spatial transformer: (y, x) transform_type ({'affine'}, required) – transformation type sampler_type ({'bilinear'}, required) – sampling type out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.SwapAxis(*args, **kwargs)

Apply swapaxis to input.

Parameters: data (Symbol) – Input data to the SwapAxisOp. dim1 (int (non-negative), optional, default=0) – the first axis to be swapped. dim2 (int (non-negative), optional, default=0) – the second axis to be swapped. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.UpSampling(*args, **kwargs)

Perform nearest neighboor/bilinear up sampling to inputs This function support variable length of positional input.

Parameters: data (Symbol[]) – Array of tensors to upsample scale (int (non-negative), required) – Up sampling scale num_filter (int (non-negative), optional, default=0) – Input filter. Only used by bilinear sample_type. sample_type ({'bilinear', 'nearest'}, required) – upsampling method multi_input_mode ({'concat', 'sum'},optional, default='concat') – How to handle multiple input. concat means concatenate upsampled images along the channel dimension. sum means add all images together, only available for nearest neighbor upsampling. num_args (int, required) – Number of inputs to be upsampled. For nearest neighbor upsampling, this can be 1-N; the size of output will be(scale*h_0,scale*w_0) and all other inputs will be upsampled to thesame size. For bilinear upsampling this must be 2; 1 input and 1 weight. workspace (long (non-negative), optional, default=512) – Tmp workspace for deconvolution (MB) out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.abs(*args, **kwargs)

Take absolute value of the src

From:src/operator/tensor/elemwise_unary_op.cc:83

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.adam_update(*args, **kwargs)

Parameters: lr (float, required) – learning_rate beta1 (float, optional, default=0.9) – beta1 beta2 (float, optional, default=0.999) – beta2 epsilon (float, optional, default=1e-08) – epsilon wd (float, optional, default=0) – weight decay rescale_grad (float, optional, default=1) – rescale gradient as grad = rescale_grad*grad. clip_gradient (float, optional, default=-1) – If greater than 0, clip gradient to grad = max(min(grad, -clip_gradient), clip_gradient). Otherwise turned off. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.arccos(*args, **kwargs)

Take arccos of the src

From:src/operator/tensor/elemwise_unary_op.cc:236

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.arccosh(*args, **kwargs)

Take arccosh of the src

From:src/operator/tensor/elemwise_unary_op.cc:308

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.arcsin(*args, **kwargs)

Take arcsin of the src

From:src/operator/tensor/elemwise_unary_op.cc:227

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.arcsinh(*args, **kwargs)

Take arcsinh of the src

From:src/operator/tensor/elemwise_unary_op.cc:299

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.arctan(*args, **kwargs)

Take arctan of the src

From:src/operator/tensor/elemwise_unary_op.cc:245

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.arctanh(*args, **kwargs)

Take arctanh of the src

From:src/operator/tensor/elemwise_unary_op.cc:317

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.argmax(*args, **kwargs)

Compute argmax

Parameters: data (NDArray) – Source input axis (int, optional, default='-1') – Empty or unsigned. The axis to perform the reduction.If left empty, a global reduction will be performed. keepdims (boolean, optional, default=False) – If true, the axis which is reduced is left in the result as dimension with size one. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.argmax_channel(*args, **kwargs)
Parameters: src (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.argmin(*args, **kwargs)

Compute argmin

Parameters: data (NDArray) – Source input axis (int, optional, default='-1') – Empty or unsigned. The axis to perform the reduction.If left empty, a global reduction will be performed. keepdims (boolean, optional, default=False) – If true, the axis which is reduced is left in the result as dimension with size one. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.argsort(*args, **kwargs)

Returns the indices that would sort an array.

From:src/operator/tensor/ordering_op.cc:89

Parameters: src (NDArray) – Source input axis (int or None, optional, default='-1') – Axis along which to sort the input tensor. If not given, the flattened array is used. Default is -1. is_ascend (boolean, optional, default=True) – Whether sort in ascending or descending order. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.batch_dot(*args, **kwargs)

Calculate batched dot product of two matrices. (batch, M, K) X (batch, K, N) –> (batch, M, N).

From:src/operator/tensor/matrix_op.cc:269

Parameters: lhs (NDArray) – Left input rhs (NDArray) – Right input transpose_a (boolean, optional, default=False) – True if the first matrix is transposed. transpose_b (boolean, optional, default=False) – True if the second matrix is tranposed. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.batch_take(*args, **kwargs)

Take scalar value from a batch of data vectos according to an index vector, i.e. out[i] = a[i, indices[i]]. out of bound indices are clipped to boundary.

From:src/operator/tensor/indexing_op.cc:100

Parameters: a (NDArray) – Input data array indices (NDArray) – index array out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_add(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_axis(*args, **kwargs)

Parameters: data (NDArray) – Source input axis (Shape(tuple), optional, default=()) – The axes to perform the broadcasting. size (Shape(tuple), optional, default=()) – Target sizes of the broadcasting axes. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_div(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_equal(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_greater(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_greater_equal(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_hypot(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_lesser(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_lesser_equal(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_maximum(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_minimum(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_minus(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_mul(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_not_equal(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_plus(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_power(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_sub(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.broadcast_to(*args, **kwargs)

Broadcast src to shape. If shape[i] is 0, input size will be preserved for axis i.

Parameters: data (NDArray) – Source input shape (Shape(tuple), optional, default=()) – The shape of the desired array. We can set the dim to zero if it’s same as the original. E.g A = broadcast_to(B, shape=(10, 0, 0)) has the same meaning as A = broadcast_axis(B, axis=0, size=10). out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.cast(*args, **kwargs)

Convert data type to dtype

From:src/operator/tensor/elemwise_unary_op.cc:58

Parameters: data (NDArray) – Source input dtype ({'float16', 'float32', 'float64', 'int32', 'uint8'}, required) – Output data type. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.ceil(*args, **kwargs)

Take ceil of the src

From:src/operator/tensor/elemwise_unary_op.cc:107

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.choose_element_0index(*args, **kwargs)

Choose one element from each line(row for python, column for R/Julia) in lhs according to index indicated by rhs. This function assume rhs uses 0-based index.

Parameters: lhs (NDArray) – Left operand to the function. rhs (NDArray) – Right operand to the function. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.clip(*args, **kwargs)

Clip ndarray elements to range (a_min, a_max)

From:src/operator/tensor/matrix_op.cc:301

Parameters: data (NDArray) – Source input a_min (float, required) – Minimum value a_max (float, required) – Maximum value out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.cos(*args, **kwargs)

Take cos of the src

From:src/operator/tensor/elemwise_unary_op.cc:209

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.cosh(*args, **kwargs)

Take cosh of the src

From:src/operator/tensor/elemwise_unary_op.cc:281

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.crop(*args, **kwargs)

Crop the input tensor and return a new one.

• the input and output (if explicitly given) are of the same data type, and on the same device.

From:src/operator/tensor/matrix_op.cc:145

Parameters: data (NDArray) – Source input begin (, required) – starting coordinates end (, required) – ending coordinates out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.degrees(*args, **kwargs)

Take degrees of the src

From:src/operator/tensor/elemwise_unary_op.cc:254

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.dot(*args, **kwargs)

Calculate dot product of two matrices or two vectors. If matrices have more than two dimensions, will do dot over the last (or first if transpose_a is true) axis of lhs and the first (or last if transpose_b is true) axis of rhs. Shape of result array will be the rest of lhs and rhs’s axes concatenated.

From:src/operator/tensor/matrix_op.cc:243

Parameters: lhs (NDArray) – Left input rhs (NDArray) – Right input transpose_a (boolean, optional, default=False) – True if the first matrix is transposed. transpose_b (boolean, optional, default=False) – True if the second matrix is tranposed. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.elemwise_add(*args, **kwargs)
Parameters: lhs (NDArray) – first input rhs (NDArray) – second input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.exp(*args, **kwargs)

Take exp of the src

From:src/operator/tensor/elemwise_unary_op.cc:155

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.expand_dims(*args, **kwargs)

Expand the shape of array by inserting a new axis.

From:src/operator/tensor/matrix_op.cc:124

Parameters: data (NDArray) – Source input axis (int (non-negative), required) – Position (amongst axes) where new axis is to be inserted. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.expm1(*args, **kwargs)

Take exp(x) - 1 in a numerically stable way

From:src/operator/tensor/elemwise_unary_op.cc:200

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.fill_element_0index(*args, **kwargs)

Fill one element of each line(row for python, column for R/Julia) in lhs according to index indicated by rhs and values indicated by mhs. This function assume rhs uses 0-based index.

Parameters: lhs (NDArray) – Left operand to the function. mhs (NDArray) – Middle operand to the function. rhs (NDArray) – Right operand to the function. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.fix(*args, **kwargs)

Take round of the src to integer nearest 0

From:src/operator/tensor/elemwise_unary_op.cc:122

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.flip(*args, **kwargs)

Flip the input tensor along axis and return a new one.

From:src/operator/tensor/matrix_op.cc:225

Parameters: data (NDArray) – Source input axis (int, required) – The dimension to flip out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.floor(*args, **kwargs)

Take floor of the src

From:src/operator/tensor/elemwise_unary_op.cc:112

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.gamma(*args, **kwargs)

Take the gamma function (extension of the factorial function) of the src

From:src/operator/tensor/elemwise_unary_op.cc:326

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.gammaln(*args, **kwargs)

Take gammaln (log of the absolute value of gamma(x)) of the src

From:src/operator/tensor/elemwise_unary_op.cc:335

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.identity(*args, **kwargs)

Identity mapping, copy src to output

From:src/operator/tensor/elemwise_unary_op.cc:15

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.log(*args, **kwargs)

Take log of the src

From:src/operator/tensor/elemwise_unary_op.cc:161

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.log10(*args, **kwargs)

Take base-10 log of the src

From:src/operator/tensor/elemwise_unary_op.cc:167

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.log1p(*args, **kwargs)

Take log(1 + x) in a numerically stable way

From:src/operator/tensor/elemwise_unary_op.cc:191

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.log2(*args, **kwargs)

Take base-2 log of the src

From:src/operator/tensor/elemwise_unary_op.cc:173

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.max(*args, **kwargs)

Compute max along axis. If axis is empty, global reduction is performed

Parameters: data (NDArray) – Source input axis (Shape(tuple), optional, default=()) – Empty or unsigned or tuple. The axes to perform the reduction.If left empty, a global reduction will be performed. keepdims (boolean, optional, default=False) – If true, the axis which is reduced is left in the result as dimension with size one. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.max_axis(*args, **kwargs)

Compute max along axis. If axis is empty, global reduction is performed

Parameters: data (NDArray) – Source input axis (Shape(tuple), optional, default=()) – Empty or unsigned or tuple. The axes to perform the reduction.If left empty, a global reduction will be performed. keepdims (boolean, optional, default=False) – If true, the axis which is reduced is left in the result as dimension with size one. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.mean(*args, **kwargs)

Compute mean src along axis. If axis is empty, global reduction is performed

Parameters: data (NDArray) – Source input axis (Shape(tuple), optional, default=()) – Empty or unsigned or tuple. The axes to perform the reduction.If left empty, a global reduction will be performed. keepdims (boolean, optional, default=False) – If true, the axis which is reduced is left in the result as dimension with size one. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.min(*args, **kwargs)

Compute min along axis. If axis is empty, global reduction is performed

Parameters: data (NDArray) – Source input axis (Shape(tuple), optional, default=()) – Empty or unsigned or tuple. The axes to perform the reduction.If left empty, a global reduction will be performed. keepdims (boolean, optional, default=False) – If true, the axis which is reduced is left in the result as dimension with size one. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.min_axis(*args, **kwargs)

Compute min along axis. If axis is empty, global reduction is performed

Parameters: data (NDArray) – Source input axis (Shape(tuple), optional, default=()) – Empty or unsigned or tuple. The axes to perform the reduction.If left empty, a global reduction will be performed. keepdims (boolean, optional, default=False) – If true, the axis which is reduced is left in the result as dimension with size one. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.nanprod(*args, **kwargs)

Compute product of src along axis, ignoring NaN values. If axis is empty, global reduction is performed

Parameters: data (NDArray) – Source input axis (Shape(tuple), optional, default=()) – Empty or unsigned or tuple. The axes to perform the reduction.If left empty, a global reduction will be performed. keepdims (boolean, optional, default=False) – If true, the axis which is reduced is left in the result as dimension with size one. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.nansum(*args, **kwargs)

Sum src along axis, ignoring NaN values. If axis is empty, global reduction is performed

Parameters: data (NDArray) – Source input axis (Shape(tuple), optional, default=()) – Empty or unsigned or tuple. The axes to perform the reduction.If left empty, a global reduction will be performed. keepdims (boolean, optional, default=False) – If true, the axis which is reduced is left in the result as dimension with size one. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.norm(*args, **kwargs)
Parameters: src (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.normal(*args, **kwargs)

Sample a normal distribution

Parameters: loc (float, optional, default=0) – Mean of the distribution. scale (float, optional, default=1) – Standard deviation of the distribution. shape (Shape(tuple), optional, default=()) – The shape of the output ctx (string, optional, default='') – Context of output, in format [cpu|gpu|cpu_pinned](n).Only used for imperative calls. dtype ({'float32'},optional, default='float32') – DType of the output out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.one_hot(*args, **kwargs)

Given an ndarray indices filled with locations indicating where to set on_value and depth, return an output ndarray of shape (shape(indices), depth). The off_value is marked everywhere else that are not indicated in indices. If a location in the indices is negative or greater than or equal to depth, assigning on_value to that location will be ignored.

From:src/operator/tensor/indexing_op.cc:120

Parameters: indices (NDArray) – array of locations where to set on_value depth (int, required) – The dimension size at dim = axis. on_value (double, optional, default=1) – The value assigned to the locations represented by indices. off_value (double, optional, default=0) – The value assigned to the locations not represented by indices. dtype ({'float16', 'float32', 'float64', 'int32', 'uint8'},optional, default='float32') – DType of the output out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.prod(*args, **kwargs)

Compute product of src along axis. If axis is empty, global reduction is performed

Parameters: data (NDArray) – Source input axis (Shape(tuple), optional, default=()) – Empty or unsigned or tuple. The axes to perform the reduction.If left empty, a global reduction will be performed. keepdims (boolean, optional, default=False) – If true, the axis which is reduced is left in the result as dimension with size one. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.radians(*args, **kwargs)

From:src/operator/tensor/elemwise_unary_op.cc:263

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.repeat(*args, **kwargs)

Repeat elements of an array

From:src/operator/tensor/matrix_op.cc:320

Parameters: data (NDArray) – Input data array repeats (int, required) – The number of repetitions for each element. axis (int or None, optional, default='None') – The axis along which to repeat values. The negative numbers are interpreted counting from the backward. By default, use the flattened input array, and return a flat output array. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.rint(*args, **kwargs)

Take round of the src to nearest integer

From:src/operator/tensor/elemwise_unary_op.cc:117

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.rmsprop_update(*args, **kwargs)

Updater function for RMSProp optimizer. The RMSProp code follows the version in http://arxiv.org/pdf/1308.0850v5.pdf Eq(38) - Eq(45) by Alex Graves, 2013.

Parameters: lr (float, required) – learning_rate gamma1 (float, optional, default=0.95) – gamma1 gamma2 (float, optional, default=0.9) – gamma2 epsilon (float, optional, default=1e-08) – epsilon wd (float, optional, default=0) – weight decay rescale_grad (float, optional, default=1) – rescale gradient as grad = rescale_grad*grad. clip_gradient (float, optional, default=-1) – If greater than 0, clip gradient to grad = max(min(grad, -clip_gradient), clip_gradient). Otherwise turned off. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.round(*args, **kwargs)

Take round of the src

From:src/operator/tensor/elemwise_unary_op.cc:101

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.rsqrt(*args, **kwargs)

Take reciprocal square root of the src

From:src/operator/tensor/elemwise_unary_op.cc:145

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.sgd_mom_update(*args, **kwargs)

Updater function for sgd optimizer

Parameters: lr (float, required) – learning_rate momentum (float, optional, default=0) – momentum wd (float, optional, default=0) – weight decay rescale_grad (float, optional, default=1) – rescale gradient as grad = rescale_grad*grad. clip_gradient (float, optional, default=-1) – If greater than 0, clip gradient to grad = max(min(grad, -clip_gradient), clip_gradient). Otherwise turned off. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.sgd_update(*args, **kwargs)

Updater function for sgd optimizer

Parameters: lr (float, required) – learning_rate wd (float, optional, default=0) – weight decay rescale_grad (float, optional, default=1) – rescale gradient as grad = rescale_grad*grad. clip_gradient (float, optional, default=-1) – If greater than 0, clip gradient to grad = max(min(grad, -clip_gradient), clip_gradient). Otherwise turned off. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.sign(*args, **kwargs)

Take sign of the src

From:src/operator/tensor/elemwise_unary_op.cc:92

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.sin(*args, **kwargs)

Take sin of the src

From:src/operator/tensor/elemwise_unary_op.cc:182

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.sinh(*args, **kwargs)

Take sinh of the src

From:src/operator/tensor/elemwise_unary_op.cc:272

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.slice(*args, **kwargs)

Crop the input tensor and return a new one.

• the input and output (if explicitly given) are of the same data type, and on the same device.

From:src/operator/tensor/matrix_op.cc:145

Parameters: data (NDArray) – Source input begin (, required) – starting coordinates end (, required) – ending coordinates out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.slice_axis(*args, **kwargs)

Slice the input along certain axis and return a sliced array. The slice will be taken from [begin, end). end can be None and axis can be negative.

From:src/operator/tensor/matrix_op.cc:206

Parameters: data (NDArray) – Source input axis (int, required) – The axis to be sliced. Negative axis means to count from the last to the first axis. begin (int, required) – The beginning index to be sliced. Negative values are interpreted as counting from the backward. end (int or None, required) – The end index to be sliced. The end can be None, in which case all the rest elements are used. Also, negative values are interpreted as counting from the backward. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.smooth_l1(*args, **kwargs)

Calculate Smooth L1 Loss(lhs, scalar)

From:src/operator/tensor/elemwise_binary_scalar_op_extended.cc:63

Parameters: data (NDArray) – source input scalar (float) – scalar input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.softmax_cross_entropy(*args, **kwargs)

Calculate cross_entropy(data, one_hot(label))

From:src/operator/loss_binary_op.cc:12

Parameters: data (NDArray) – Input data label (NDArray) – Input label out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.sort(*args, **kwargs)

Return a sorted copy of an array.

From:src/operator/tensor/ordering_op.cc:59

Parameters: src (NDArray) – Source input axis (int or None, optional, default='-1') – Axis along which to choose sort the input tensor. If not given, the flattened array is used. Default is -1. is_ascend (boolean, optional, default=True) – Whether sort in ascending or descending order. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.sqrt(*args, **kwargs)

Take square root of the src

From:src/operator/tensor/elemwise_unary_op.cc:136

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.square(*args, **kwargs)

Take square of the src

From:src/operator/tensor/elemwise_unary_op.cc:127

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.sum(*args, **kwargs)

Sum src along axis. If axis is empty, global reduction is performed

Parameters: data (NDArray) – Source input axis (Shape(tuple), optional, default=()) – Empty or unsigned or tuple. The axes to perform the reduction.If left empty, a global reduction will be performed. keepdims (boolean, optional, default=False) – If true, the axis which is reduced is left in the result as dimension with size one. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.sum_axis(*args, **kwargs)

Sum src along axis. If axis is empty, global reduction is performed

Parameters: data (NDArray) – Source input axis (Shape(tuple), optional, default=()) – Empty or unsigned or tuple. The axes to perform the reduction.If left empty, a global reduction will be performed. keepdims (boolean, optional, default=False) – If true, the axis which is reduced is left in the result as dimension with size one. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.take(*args, **kwargs)

Take row vectors from an NDArray according to the indices For an input of index with shape (d1, ..., dK), the output shape is (d1, ..., dK, row_vector_length).All the input values should be integers in the range [0, column_vector_length).

From:src/operator/tensor/indexing_op.cc:60

Parameters: a (Symbol) – The source array. indices (Symbol) – The indices of the values to extract. axis (int, optional, default='0') – the axis of data tensor to be taken. mode ({'clip', 'raise', 'wrap'},optional, default='raise') – specify how out-of-bound indices bahave. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.tan(*args, **kwargs)

Take tan of the src

From:src/operator/tensor/elemwise_unary_op.cc:218

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.tanh(*args, **kwargs)

Take tanh of the src

From:src/operator/tensor/elemwise_unary_op.cc:290

Parameters: data (NDArray) – Source input out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.tile(*args, **kwargs)

Construct an array by repeating A the number of times given by reps.

From:src/operator/tensor/matrix_op.cc:343

Parameters: data (NDArray) – Input data array reps (Shape(tuple), required) – The number of times for repeating the tensor a. If reps has length d, the result will have dimension of max(d, a.ndim); If a.ndim < d, a is promoted to be d-dimensional by prepending new axes. If a.ndim > d, reps is promoted to a.ndim by pre-pending 1’s to it. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.topk(*args, **kwargs)

Return the top k element of an input tensor along a given axis.

From:src/operator/tensor/ordering_op.cc:18

Parameters: src (NDArray) – Source input axis (int or None, optional, default='-1') – Axis along which to choose the top k indices. If not given, the flattened array is used. Default is -1. k (int, optional, default='1') – Number of top elements to select, should be always smaller than or equal to the element number in the given axis. A global sort is performed if set k < 1. ret_typ ({'both', 'indices', 'mask', 'value'},optional, default='indices') – The return type. “value” means returning the top k values, “indices” means returning the indices of the top k values, “mask” means to return a mask array containing 0 and 1. 1 means the top k values. “both” means to return both value and indices. is_ascend (boolean, optional, default=False) – Whether to choose k largest or k smallest. Top K largest elements will be chosen if set to false. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.transpose(*args, **kwargs)

Transpose the input tensor and return a new one

From:src/operator/tensor/matrix_op.cc:96

Parameters: data (NDArray) – Source input axes (Shape(tuple), optional, default=()) – Target axis order. By default the axes will be inverted. out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.uniform(*args, **kwargs)

Sample a uniform distribution

Parameters: low (float, optional, default=0) – The lower bound of distribution high (float, optional, default=1) – The upper bound of distribution shape (Shape(tuple), optional, default=()) – The shape of the output ctx (string, optional, default='') – Context of output, in format [cpu|gpu|cpu_pinned](n).Only used for imperative calls. dtype ({'float32'},optional, default='float32') – DType of the output out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray
mxnet.ndarray.where(*args, **kwargs)

Given three ndarrays, condition, x, and y, return an ndarray with the elements from x or y, depending on the elements from condition are true or false. x and y must have the same shape. If condition has the same shape as x, each element in the output array is from x if the corresponding element in the condition is true, and from y if false. If condtion does not have the same shape as x, it must be a 1D array whose size is the same as x’s first dimension size. Each row of the output array is from x’s row if the corresponding element from condition is true, and from y’s row if false.

From:src/operator/tensor/control_flow_op.cc:21

Parameters: condition (NDArray) – condition array x (NDArray) – y (NDArray) – out (NDArray, optional) – The output NDArray to hold the result. out – The output of this function. NDArray or list of NDArray

## NDArray Random API Reference¶

Random Number interface of mxnet.

mxnet.random.seed(seed_state)

Seed the random number generators in mxnet.

This seed will affect behavior of functions in this module, as well as results from executors that contains Random number such as Dropout operators.

Parameters: seed_state (int) – The random number seed to set to all devices.

Notes

The random number generator of mxnet is by default device specific. This means if you set the same seed, the random number sequence generated from GPU0 can be different from CPU.

## Context API Reference¶

Context management API of mxnet.

class mxnet.context.Context(device_type, device_id=0)

Constructing a context.

Parameters: device_type ({'cpu', 'gpu'} or Context.) – String representing the device type device_id (int (default=0)) – The device id of the device, needed for GPU

Note

Context can also be used a way to change default context.

Examples

>>> # array on cpu
>>> cpu_array = mx.md.ones((2, 3))
>>> # switch default context to GPU(2)
>>> with mx.Context(mx.gpu(2)):
>>>     gpu_array = mx.md.ones((2, 3))
>>> gpu_array.context
gpu(2)

device_type

Return device type of current context.

Returns: device_type str
mxnet.context.cpu(device_id=0)

Return a CPU context.

This function is a short cut for Context(‘cpu’, device_id)

Parameters: device_id (int, optional) – The device id of the device. device_id is not needed for CPU. This is included to make interface compatible with GPU. context – The corresponding CPU context. Context
mxnet.context.gpu(device_id=0)

Return a GPU context.

This function is a short cut for Context(‘gpu’, device_id)

Parameters: device_id (int, optional) – The device id of the device, needed for GPU context – The corresponding GPU context. Context
mxnet.context.current_context()

Return the current context.

Returns: default_ctx Context