Python 创建长度为20,取值范围为10-20 的一维数组
在 Python 中,可以使用 NumPy 库来创建长度为 20,取值范围为 10-20 的一维数组。以下代码示例演示了如何实现:
import numpy as np
array = np.random.randint(10, 21, 20)
print(array)
输出结果类似于:
[20 11 19 12 13 13 11 11 14 19 19 12 15 10 11 11 12 16 19 13]
其中,np.random.randint(10, 21, 20) 表示从 10 到 20 之间(包括 10 和 20)随机生成 20 个整数,并将它们赋值给数组 array。
原文地址: https://www.cveoy.top/t/topic/ozoL 著作权归作者所有。请勿转载和采集!