Question #7021
Submitted by Answiki
on 10/30/2022 at 07:51:05 PM UTC
In Python, how do you go from a list to a one-column array?
Merged questions
Answer
Submitted by Answiki
on 10/30/2022 at 07:52:22 PM UTC
In Python, the best way to switch from a list to a one-column array is to use the pn.c_
object. Here is an example:
>>> import numpy as np
>>> myList = [1,2,4,8]
>>> print (np.c_[myList])
[[1]
[2]
[4]
[8]]
This object is actually a shortcut to np.r_['-1,2,0', myList]
which returns the same result:
>>> print (np.r_['-1,2,0', myList])
[[1]
[2]
[3]
[4]]
Answer by Answiki on 10/30/2022 at 07:52:22 PM
In Python, the best way to switch from a list to a one-column array is to use the pn.c_
object. Here is an example:
>>> import numpy as np
>>> myList = [1,2,4,8]
>>> print (np.c_[myList])
[[1]
[2]
[4]
[8]]
This object is actually a shortcut to np.r_['-1,2,0', myList]
which returns the same result:
>>> print (np.r_['-1,2,0', myList])
[[1]
[2]
[3]
[4]]
Question by Answiki 10/30/2022 at 07:51:05 PM
In Python, how do you go from a list to a one-column array?
# | ID | Query | URL | Count |
---|
Icons proudly provided by Friconix.