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
Post a Comment