Reputation: 1960
I have an array of probabilities:
l = [0.9, 0.2, 0.4]
and I want to make it 2d array:
l = [0.9 0.1
0.2 0.8
0.4 0.6]
What is the best way to do so?
Upvotes: 1
Views: 113
Reputation: 862611
One idea is use numpy.hstack
:
l = [0.9, 0.2, 0.4]
a = np.array(l)[:, None]
arr = np.hstack((a, 1 - a))
print (arr)
[[0.9 0.1]
[0.2 0.8]
[0.4 0.6]]
Or use numpy.c_
:
a = np.array(l)
arr = np.c_[a, 1 - a]
print (arr)
Upvotes: 2