标签: python scipy
我想这样做:
假设我有N=100和myone=scipy.ones(N),其形状为:myone.shape=100, 我希望将数组myzeros=scipy.zeros(c*N),c=0.1随机插入myone数组,而不更改myone的维度。
N=100
myone=scipy.ones(N)
myone.shape=100
myzeros=scipy.zeros(c*N)
c=0.1
myone
答案 0 :(得分:2)
import scipy as sc myone = sc.ones(100) ind = sc.random.permutation(100)[:10] myone[ind] = 0