NumpyTensor.asarray

NumpyTensor.asarray(self, out=None)[source]

Extract the data of this array as a numpy.ndarray.

This method is invoked when calling numpy.asarray on this tensor.

Parameters
outnumpy.ndarray, optional

Array in which the result should be written in-place. Has to be contiguous and of the correct dtype.

Returns
asarraynumpy.ndarray

Numpy array with the same data type as self. If out was given, the returned object is a reference to it.

Examples

>>> space = odl.rn(3, dtype='float32')
>>> x = space.element([1, 2, 3])
>>> x.asarray()
array([ 1.,  2.,  3.], dtype=float32)
>>> np.asarray(x) is x.asarray()
True
>>> out = np.empty(3, dtype='float32')
>>> result = x.asarray(out=out)
>>> out
array([ 1.,  2.,  3.], dtype=float32)
>>> result is out
True
>>> space = odl.rn((2, 3))
>>> space.one().asarray()
array([[ 1.,  1.,  1.],
       [ 1.,  1.,  1.]])