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
  • 826
  • 8
  • 15

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,500
  • 1
  • 16
  • 26