mirror of
https://github.com/wassname/pytorch-for-numpy-users.git
synced 2026-06-27 16:10:21 +08:00
30 lines
1.1 KiB
Markdown
30 lines
1.1 KiB
Markdown
# PyTorch for Numpy users
|
|
|
|
[PyTorch](https://github.com/pytorch/pytorch.git) version of [_Torch for Numpy users_](https://github.com/torch/torch7/wiki/Torch-for-Numpy-users).
|
|
|
|
|
|
## Types
|
|
|
|
| Numpy | PyTorch |
|
|
|:-------------|:---------------------|
|
|
| `np.uint8` | `torch.ByteTensor` |
|
|
| `np.int32` | `torch.IntTensor` |
|
|
| `np.int64` | `torch.LongTensor` |
|
|
| `np.float32` | `torch.FloatTensor` |
|
|
| `np.float64` | `torch.DoubleTensor` |
|
|
|
|
## Constructors
|
|
|
|
| Numpy | PyTorch |
|
|
|:-------------------|:---------------------------------------|
|
|
| `np.empty((2, 3))` | `torch.Tensor(2, 3)` |
|
|
| `np.empty_like(x)` | `x.new(x.size()).type(x.type())` |
|
|
| `np.eye` | `torch.eye` |
|
|
| `np.identity` | `torch.eye` |
|
|
| `np.ones` | `torch.ones` |
|
|
| `np.ones_like` | `torch.ones(x.size()).type(x.type())` |
|
|
| `np.zeros` | `torch.zeros` |
|
|
| `np.zeros_like` | `torch.zeros(x.size()).type(x.type())` |
|
|
|
|
|