Convert this array to numpy array Returns ------- np_arr : numpy.ndarray The corresponding numpy array.
(self)
| 323 | return str(self.asnumpy()) |
| 324 | |
| 325 | def asnumpy(self): |
| 326 | """Convert this array to numpy array |
| 327 | |
| 328 | Returns |
| 329 | ------- |
| 330 | np_arr : numpy.ndarray |
| 331 | The corresponding numpy array. |
| 332 | """ |
| 333 | t = DGLDataType(self.dtype) |
| 334 | shape, dtype = self.shape, self.dtype |
| 335 | if t.lanes > 1: |
| 336 | shape = shape + (t.lanes,) |
| 337 | t.lanes = 1 |
| 338 | dtype = str(t) |
| 339 | np_arr = np.empty(shape, dtype=dtype) |
| 340 | assert np_arr.flags["C_CONTIGUOUS"] |
| 341 | data = np_arr.ctypes.data_as(ctypes.c_void_p) |
| 342 | nbytes = ctypes.c_size_t(np_arr.size * np_arr.dtype.itemsize) |
| 343 | check_call(_LIB.DGLArrayCopyToBytes(self.handle, data, nbytes)) |
| 344 | return np_arr |
| 345 | |
| 346 | def copyto(self, target): |
| 347 | """Copy array to target |