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
- out
numpy.ndarray
, optional Array in which the result should be written in-place. Has to be contiguous and of the correct dtype.
- out
- Returns
- asarray
numpy.ndarray
Numpy array with the same data type as
self
. Ifout
was given, the returned object is a reference to it.
- asarray
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.]])