Skip to content

[Feature request] A few things that numpy does that pytorch could have #1875

@martinarjovsky

Description

@martinarjovsky

Hi! Small list of simple features that I used on a day to day basis both in numpy and theano and would be helpful to have now. They're all super dumb, but writing hack-arounds or debugging a few extra things is sometimes annoying, and they should be super easy to add.

  • Add .mean() for ByteTensors so we can calculate accs easily.
x = torch.Tensor(3).normal_()
(x > 0).mean() # Throws error

y = np.random.randn(3)
(y > 0).mean() # Works ok
  • It's weird that .random_() defaults to garbage and not U[0,1] or something like that. Seems very error prone (I myself had to debug this ~ 10 times). Maybe a warning at least?
x = torch.Tensor(2,3)
x.random_() # Returns random ints from 0 to max_int?

y = np.random.random((2,3)) # Returns U[0,1] on each entry
  • Having something like ones_like and zeros_like would be ideal! I used to use this all the time for masks and other things. Also the hack arounds are very prone to do a bad use of memory, as opposed to the expand_as [esp when the programmer is bad such as myself :) ].
y = np.random.rand(3)
z = np.ones_like(y)
  • It's very annoying that torch.arange returns a FloatTensor and index_select requires a LongTensor. I guess when advanced indexing is in this won't matter :)

  • Edit: Adding that np.arange works just by specifying the end (as range) and torch.arange doesn't. Also the numpy version has dtypo int64 while the torch one is a FloatTensor, though similar things like torch.randperm give LongTensor (this might be useful, idk).

y = np.arange(10) # [0, ..., 9]
x = torch.arange(10) # Hell unleashes

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureA request for a proper, new feature.proposal acceptedThe core team has reviewed the feature request and agreed it would be a useful addition to PyTorchtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions