Copy the tensor into a numpy array. Args: t (Tensor): a Tensor Returns: a numpy array
(t)
| 889 | |
| 890 | |
| 891 | def to_numpy(t): |
| 892 | '''Copy the tensor into a numpy array. |
| 893 | |
| 894 | Args: |
| 895 | t (Tensor): a Tensor |
| 896 | |
| 897 | Returns: |
| 898 | a numpy array |
| 899 | ''' |
| 900 | th = to_host(t) |
| 901 | if th.dtype == float32: |
| 902 | np_array = th.data.GetFloatValue(int(th.size())) |
| 903 | elif th.dtype == int32: |
| 904 | np_array = th.data.GetIntValue(int(th.size())) |
| 905 | else: |
| 906 | print('Not implemented yet for ', th.dtype) |
| 907 | return np_array.reshape(th.shape) |
| 908 | |
| 909 | |
| 910 | def abs(t): |