python - making multi-dimensional nulls or ones from numpy array -


i want create array filled ones or zeros based on array

testarray = np.array([7,5,3]) 

so final result should like

[[1,1,1,1,1,1,1],  [1,1,1,1,1],  [1,1,1]] 

this give ragged array of object dtype:

>>> result = np.array([np.ones(a) in testarray]) >>> print result [[ 1.  1.  1.  1.  1.  1.  1.] [ 1.  1.  1.  1.  1.] [ 1.  1.  1.]] 

for zeros, use np.zeros.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -