How to generate a random integer tensor?

3,548 views
Skip to first unread message

Minh Lê

unread,
Aug 21, 2015, 6:37:08 PM8/21/15
to torch7
Hi everyone,

I found only torch.rand() but nothing like NumPy randint. Could anyone show me how to do it?

Best regards,
Minh

Francisco Vitor Suzano Massa

unread,
Aug 21, 2015, 6:50:59 PM8/21/15
to torch7
Just define a tensor
t = torch.Tensor (5)

and then use the :random() function

t:random (3,12)

will generate random numbers from 3 to 12

Minh Lê

unread,
Aug 21, 2015, 6:53:16 PM8/21/15
to torch7 on behalf of Francisco Vitor Suzano Massa
That's easy, thanks a lot!

Minh

--
You received this message because you are subscribed to a topic in the Google Groups "torch7" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/torch7/zQRgzXoDiwE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to torch7+un...@googlegroups.com.
To post to this group, send email to tor...@googlegroups.com.
Visit this group at http://groups.google.com/group/torch7.
For more options, visit https://groups.google.com/d/optout.

Tim Zaman

unread,
Apr 9, 2016, 8:38:23 PM4/9/16
to torch7
NB * to and including 12
Reply all
Reply to author
Forward
0 new messages