1

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?

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.