Returns the value of this tensor as a nested list. Returns single value for const tensor. ```python exec="true" source="above" session="tensor" result="python" t = Tensor([1, 2, 3, 4]) print(t.tolist()) ``` ```python exec="true" source="above" session="tensor" result="p
(self)
| 321 | |
| 322 | # NOTE: list[Any] because return type is recursive (list[list[...]] for higher dimensions) |
| 323 | def tolist(self) -> PyConst|list[Any]: |
| 324 | """ |
| 325 | Returns the value of this tensor as a nested list. |
| 326 | Returns single value for const tensor. |
| 327 | |
| 328 | ```python exec="true" source="above" session="tensor" result="python" |
| 329 | t = Tensor([1, 2, 3, 4]) |
| 330 | print(t.tolist()) |
| 331 | ``` |
| 332 | ```python exec="true" source="above" session="tensor" result="python" |
| 333 | t = Tensor(5) |
| 334 | print(t.tolist()) |
| 335 | ``` |
| 336 | """ |
| 337 | # TODO: remove half once minimum python supports it |
| 338 | if self.dtype in (dtypes.half, dtypes.bfloat16, *dtypes.fp8s): return self.cast(dtypes.float32).tolist() |
| 339 | return self.data().tolist() |
| 340 | |
| 341 | def numpy(self) -> 'numpy.ndarray': |
| 342 | """ |