2

Consider these two one-dimensional array of tuples and array

a = [ (x,x,x)  for x=1:5 ]
b = [ [x,x,x]  for x=1:5 ]
c = [ {x,x,x}  for x=1:5 ]

What is the easiest way to format these arrays a b or c into the array d?

d = reshape(repeat([x for x=1:5],outer=[3]),5,3)
5x3 Array{Int64,2}:
 1  1  1
 2  2  2
 3  3  3
 4  4  4
 5  5  5

1 Answer 1

1

Due to the auto-concatenation that happens with vectors, the best (shortest) way for b and c is

hcat(b...)'

For a, because they are tuples, I'd do something like

hcat(map(t->[t...],a)...)'

where I'm converting the tuples to arrays, then concatenating them.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot lainDunning!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.