我想在intervalle [0,100]中生成一个包含随机整数(坐标)的随机3d数组。
所以,coordinates=dim(30,10,2)
我尝试了什么?
coordinates = [[random.randint(0,100), random.randint(0,100)] for _i in range(30)]
返回
array([[97, 68],
[11, 23],
[47, 99],
[52, 58],
[95, 60],
[89, 29],
[71, 47],
[80, 52],
[ 7, 83],
[30, 87],
[53, 96],
[70, 33],
[36, 12],
[15, 52],
[30, 76],
[61, 52],
[87, 99],
[19, 74],
[37, 63],
[40, 2],
[ 8, 84],
[70, 32],
[63, 8],
[98, 89],
[27, 12],
[75, 59],
[76, 17],
[27, 12],
[48, 61],
[39, 98]])
形状(30,10)
我应该得到什么?
dim =(30,10,2)而不是(30,10)
答案 0 :(得分:2)
import numpy as np
coordinates = np.random.randint(0, 100, size=(30, 10, 2))
将生成一个NumPy数组,其整数值介于0到100之间,形状为(30, 10, 2)
。