Table Of Contents
Table Of Contents


mxnet.ndarray.array(source_array, ctx=None, dtype=None)[source]

Creates an array from any object exposing the array interface.

  • source_array (array_like) – An object exposing the array interface, an object whose __array__ method returns an array, or any (nested) sequence.

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

  • dtype (str or numpy.dtype, optional) – The data type of the output array. The default dtype is source_array.dtype if source_array is an NDArray, float32 otherwise.


An array with the same contents as the source_array.

Return type

NDArray, RowSparseNDArray or CSRNDArray


>>> import numpy as np
>>> mx.nd.array([1, 2, 3])
<NDArray 3 @cpu(0)>
>>> mx.nd.array([[1, 2], [3, 4]])
<NDArray 2x2 @cpu(0)>
>>> mx.nd.array(np.zeros((3, 2)))
<NDArray 3x2 @cpu(0)>
>>> mx.nd.array(np.zeros((3, 2)), mx.gpu(0))
<NDArray 3x2 @gpu(0)>
>>> mx.nd.array(mx.nd.zeros((3, 2), stype='row_sparse'))
<RowSparseNDArray 3x2 @cpu(0)>