Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

arrays - 如何在Julia中将一维数组转换为元组?(How to convert a 1D array to tuple in Julia?)

I want to reshape an array in Julia using the reshape function but the shape of the new array is stored as a 1-D array itself.

(我想使用reshape函数在Julia中对数组进行整形,但是新数组的形状本身存储为一维数组。)

reshape takes tuples as argument but not 1D array.

(reshape将元组作为参数,而不是一维数组。)

For example, I want to be able to do this:

(例如,我希望能够做到这一点:)

reshape([1 2 3 ; 4 5 6],(3,2))

but using [3,2] instead of (3,2) as the input to the shape parameter.

(但使用[3,2]代替(3,2)作为shape参数的输入。)

Converting array [3,2] to tuple (3,2) seems like the obvious thing to do, but if that can't be done, maybe I need to write another reshape function?

(将数组[3,2]转换为元组(3,2)似乎是显而易见的事情,但是如果无法完成,也许我需要编写另一个reshape函数?)

Any advice is appreciated.

(任何建议表示赞赏。)

  ask by truedichotomy translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can splat the array:

(您可以图示数组:)

julia> reshape([1 2 3 ; 4 5 6], [3,2]...)
3×2 Array{Int64,2}:
 1  5
 4  3
 2  6

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...