Reputation: 35
I want a matrix not the same shape as another matrix, but with the shape the other matrix holds.
shape=[2,3]
matrix=zeros(shape)
size(matrix)=(2,)
How can I get size(matrix)=shape
?
I could do it like this:
matrix=zeros(shape[1],shape[2])
is there a more generic way to do it?
Upvotes: 1
Views: 185
Reputation: 18217
try zeros(shape...)
. The splat operator ...
turns a vector into parameters for a function:
v = [a,b,c]
func(v...) # is the same as
func(a,b,c)
and it works for tuples too:
t = (a,b,c)
func(t...) # is the same as
func(a,b,c)
Upvotes: 3