Tensor.asarray
- Tensor.asarray(out=None, must_be_contiguous: bool = False)[source]
Extract the data of this array as a backend-specific array/tensor.
This method is invoked when calling
numpy.asarrayon this tensor.Parameters
- outarray_like, optional
Array in which the result should be written in-place. Has to be contiguous and of the correct backend, dtype and device.
- must_be_contiguous:
bool If this is
True, then the returned array must occupy a single block of memory and the axes be ordered (in C order). Cf.numpy.ascontiguousarray. This may require making a copy. IfFalseis given, the returned array may be a view or have transposed axes, if this allows avoiding a copy. If anoutargument is provided,must_be_contiguousis irrelevant.
Returns
- asarrayarray_like
Numpy array, pytorch tensor or similar with the same data type as
self. Ifoutwas 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) >>> 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.]])