2

I have a vector composed of 10 elements and I want to "split" it into two vectors composed of five elements:

q={1,2,3,4,5,6,7,8,9,10};Partition[q,5]

but the output is a matrix...

{{1,2,3,4,5},{6,7,8,9,10}}

How can I obtain 2 separated vectors rather than a matrix?

Gae P
  • 637
  • 3
  • 11
  • 2
    What are 'two separated vectors'? Sequence @@ Partition[q,5]? It will still have Sequence head but that is the closest concept I suppose. – Kuba Jun 22 '17 at 15:10
  • @tomd: Huh? Doesn't your answer give precisely what the poser's (unsatisfactory) answer gives? – David G. Stork Jun 22 '17 at 16:05
  • Don't think of it as a matrix, think of it as a list of vectors. You can do [[1]] or //First or any other list operation to extract the first and second vectors. – 1110101001 Jun 22 '17 at 19:45

2 Answers2

6

How about:

q = {1,2,3,4,5,6,7,8,9,10};
{part1, part2} = Partition[q,5]

Now you have two separate lists (part1 and part2), each containing half of the partitioned q.

bill s
  • 68,936
  • 4
  • 101
  • 191
5

The output of a line of Mathematica code is a single element, so

Partition[q,5]

is all you can get. If you want to access the parts individually:

Partition[q,5][[1]] 

and

Partition[q,5][[2]] 

What exactly do you want this for? (That will help us help you.)

David G. Stork
  • 41,180
  • 3
  • 34
  • 96