mxnet.np.array

array(object, dtype=None, device=None)

Create an array.

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

  • dtype (data-type, optional) –

    The desired data-type for the array. The default dtype is object.dtype if object is an ndarray, float32 otherwise. Default dtype can be set to be consistent with offical numpy by npx.set_np(dtype=True).

    • When npx.is_np_default_dtype() returns False, default dtype is float32;

    • When npx.is_np_default_dtype() returns True, default dtype is float64.

  • device (Device, optional) – Device context on which the memory is allocated. Default is mxnet.device.current_device().

Returns

out – An array object satisfying the specified requirements.

Return type

ndarray

Examples

>>> np.array([1, 2, 3])
array([1., 2., 3.])
>>> np.array([[1, 2], [3, 4]])
array([[1., 2.],
       [3., 4.]])
>>> np.array([[1, 0], [0, 1]], dtype=bool)
array([[ True, False],
       [False,  True]])
>>> np.array([1, 2, 3]).dtype
dtype('float32')
>>> npx.set_np(dtype=True)
>>> np.array([1, 2, 3]).dtype
dtype('float64')