如想生成有4个0,6个1的随机数组,代码如下:
import numpy as np
nums = np.ones(10)
nums[:4] = 0
np.random.shuffle(nums)
print(nums)
运行结果:
[1. 0. 0. 1. 0. 1. 0. 1. 1. 1.]
完美( ̄▽ ̄)~*
如想生成有4个0,6个1的随机数组,代码如下:
import numpy as np
nums = np.ones(10)
nums[:4] = 0
np.random.shuffle(nums)
print(nums)
运行结果:
[1. 0. 0. 1. 0. 1. 0. 1. 1. 1.]
完美( ̄▽ ̄)~*