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]].
Asked
Active
Viewed 5,150 times
1 Answers
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