I have 3 lists and I need them to be 1 np.array() with 3 rows. The append method has not been working because it is created 3 separate arrays.
A = array([[1, 4, 1],
[4, 1, 9],
[1, 9, 1]])
[0.01665703 0.06662812 0.01665703]
[0.00049017 0.00012254 0.00110289]
[0.00012333 0.00110994 0.00012333]
ideal output (dtype: numpy.ndarray):
[[0.01665703 0.06662812 0.01665703]
[0.00049017 0.00012254 0.00110289]
[0.00012333 0.00110994 0.00012333]]
Attempted Code:
em = []
for list in A:
result = list / np.exp(list).sum(axis=0)
em.append(result)
Attempted code's output:
[array([0.01665703, 0.06662812, 0.01665703]),
array([0.00049017, 0.00012254, 0.00110289]),
array([0.00012333, 0.00110994, 0.00012333])]
CodePudding user response:
import numpy as np
list_1 = [0.01665703, 0.06662812, 0.01665703]
list_2 = [0.00049017, 0.00012254, 0.00110289]
list_3 = [0.00012333, 0.00110994, 0.00012333]
combined = np.array([
list_1,
list_2,
list_3
])
CodePudding user response:
Is this what you want? This gives you the ideal output you specified. probably not the best way to do it, but it works
import numpy as np
myList_1 = [0.01665703, 0.06662812, 0.01665703]
myList_2 = [0.00049017, 0.00012254, 0.00110289]
myList_3 = [0.00012333, 0.00110994, 0.00012333]
print(np.array([myList_1, myList_2, myList_3]))
