Skip to content

Inferring NumPy array type when using from_numpy #541

@rasbt

Description

@rasbt

Hi,
I love the PyTorch library so far, but I wanted to note one little annoyance that I encountered -- something that could be improved in future. For instance, when I convert numpy arrays to torch tensors, it disregards the original NumPy type and creates torch.DoubleTensor /torch.cuda.DoubleTensors. I think it would make more sense to inherit the array type float, int, etc. to create the tensors.

Here's a simple example:

import numpy as np
import torch

y = np.array([[1., 2., 3.],
              [4., 5., 6.]])

torch.from_numpy(y)

Output:

1  2  3
4  5  6
[torch.DoubleTensor of size 2x3]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions