Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interleave arrays in julia

Tags:

arrays

julia

Is it possible to interleave two arrays in julia?

For example if a=[1:10] and b=[11:20] I want to be able to return

20-element Array{Int64,1}:
  1
  11
  2
  12
  3
  13
  4
  14
  .
  .
  .

Somewhat similar to what ruby can do Merge and interleave two arrays in Ruby

like image 566
bdeonovic Avatar asked Jun 06 '14 13:06

bdeonovic


1 Answers

Figured it out!

reshape([a b]',20,1)

and for something more general:

reshape([a b].',size(a,1)+size(b,1),1)

we can use a hack to get vectors instead of 1D arrays:

reshape([a b].',size(a,1)+size(b,1),1)[:]
like image 157
bdeonovic Avatar answered Oct 22 '22 07:10

bdeonovic