1

I would like to convert a python list to a Vector (a matrix with a single column). Example: [1, 2, 3] should become [[1], [2], [3]].

Peter K
  • 1,959
  • 1
  • 16
  • 22

1 Answers1

5

Use list comprehension:

>>> [[i] for i in [1,2,3]]
[[1], [2], [3]]

or you can also use map and lambda:

>>> map(lambda x: [x], [1, 2, 3])
[[1], [2], [3]]
akash karothiya
  • 5,736
  • 1
  • 19
  • 29