2
有没有办法让一个NxN数组(所以2d数组)的元素,其中每个元素是一个3个数字在0和1之间随机选择的数组?做一个NxN数组的1x3随机数组(python)
输出应该是这个样子:
(0.2,0.45,0.98), (0.7,0.58,0.11) ...
(1.0,0.05,0.63, ...
.
.
.
等
我一直想这样做,但必须有一个更优雅的方式。下面的代码包括:
import numpy as np
import matplotlib.pyplot as plt
lat = []
for _ in range(2):
w = []
for _ in range(2):
a = np.random.uniform(0.0,1.0)
b = np.random.uniform(0.0,1.0)
c = np.random.uniform(0.0,1.0)
D = np.array([a,b,c])
w.append(D)
lat.append(w)
if _ >= 1:
np.hstack(lat)
所以,如果我使用: np.random.rand(3,3,3) 这给了我,我的问题,但与三个要素进入第三个维度所以它就像一个数据描述的矩阵立方体。 谢谢CoryKramer! – user8188120