Create a 2D vector from a 1D vector in Python

2
  • I have a vector with the following values:

    a = [10, 20, 30, 40, 50, 60, 70, 80]

  • I need to create 2D vector with these values. For example, it would have to look like this:

    b = [[10, 20], [30,40], [50,60], [70,80]]

Could someone please help me with this?

Thanks in advance, to those who can.

    
asked by anonymous 11.08.2017 / 18:59

1 answer

2

You can do something like this:

b = [a[i:i+2] for i in range (0, len(a), 2]
    
11.08.2017 / 19:34