'Generate sequential numbers between 0 and 1 with equal distance
I am generating random variables in my array:
np.random.rand(5,3,20)
How can I create the same shape and size but sequentially between 0 and 1?
Solution 1:[1]
Another option:
#start:stop:stepj inside np.r_ is interpreted as np.linspace(start, stop, step, endpoint=1) inside of the brackets
np.r_[0:1:300j].reshape(5,3,20)
Solution 2:[2]
Just use:
np.linspace(0, 1, num=5).reshape((5, 3))
and set the num param to implicitly define how big needs to be your step.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Allen Qin |
| Solution 2 | Asclepius |
