Returns a numpy array or a scalar with the same contents as the Tensor. TODO(ashankar,agarwal): Perhaps this should NOT reference the underlying buffer but instead always explicitly copy? Note that currently it may or may not copy based on whether the numpy data is properly aligned or n
(self)
| 916 | return dtypes._INTERN_TABLE[self._datatype_enum()] # pylint: disable=protected-access |
| 917 | |
| 918 | def numpy(self): |
| 919 | """Returns a numpy array or a scalar with the same contents as the Tensor. |
| 920 | |
| 921 | TODO(ashankar,agarwal): Perhaps this should NOT reference the underlying |
| 922 | buffer but instead always explicitly copy? Note that currently it may or may |
| 923 | not copy based on whether the numpy data is properly aligned or not. |
| 924 | |
| 925 | Returns: |
| 926 | A numpy array or a scalar. Numpy array may share memory with the |
| 927 | Tensor object. Any changes to one may be reflected in the other. A scalar |
| 928 | value is returned when self has rank 0. |
| 929 | |
| 930 | Raises: |
| 931 | ValueError: if the type of this Tensor is not representable in numpy. |
| 932 | """ |
| 933 | maybe_arr = self._numpy() # pylint: disable=protected-access |
| 934 | return maybe_arr.copy() if isinstance(maybe_arr, np.ndarray) else maybe_arr |
| 935 | |
| 936 | @property |
| 937 | def backing_device(self): |