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?
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?
Create evenly spaced numbers over a specified interval using linspace
and then reshape
to shape required as follows:
np.linspace(0, 1, 300).reshape(5, 3, 20)
Note:
'The new shape should be compatible with the original shape'
So let's say,
for np.linspace(0, 1, t).reshape(x, y, z)
the condition that should be met is t = x*y*z
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.
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)