首页 > 解决方案 > How to create a single element array and group them into a single array in python

问题描述

If I run the code below:

import numpy as np

np.random.binomial(n=1, p=0.2, size=[10])

I get (you may get something different because of randomness)

array([0, 1, 0, 0, 0, 0, 0, 0, 0, 0])

How do I get the results to be in this format?

array([ [0], [1], [0], [0], [0], [0], [0], [0], [0], [0] ])

I've tried np.array. Any suggestion? I'm making a label for neural network problem.

标签: pythonarraysnumpy

解决方案


推荐阅读