使用网格搜索在Python中创建维度为n*3的矩阵

使用网格搜索在Python中创建维度为n*3的矩阵,python,matrix,grid-search,Python,Matrix,Grid Search,我想要一个如下的矩阵,3列,n行。每行加一 [[0, 0, 1], [0, 0.1, 0.9], [0.1, 0.1, 0.8], [0.1, 0.2, 0.7] ...] 是否有用于执行此操作的库?您可以使用itertools.combinations\u与\u replacement从0.0和1.0之间的11个插槽中选择2个分区: from itertools import combinations_with_replacement [[n / 10 for n in (a, b - a,

我想要一个如下的矩阵,3列,n行。每行加一

[[0, 0, 1], [0, 0.1, 0.9], [0.1, 0.1, 0.8], [0.1, 0.2, 0.7] ...]

是否有用于执行此操作的库?

您可以使用
itertools.combinations\u与\u replacement
从0.0和1.0之间的11个插槽中选择2个分区:

from itertools import combinations_with_replacement
[[n / 10 for n in (a, b - a, 10 - b)] for a, b in combinations_with_replacement(range(11), 2)]
这将返回:

[[0.0, 0.0, 1.0],
 [0.0, 0.1, 0.9],
 [0.0, 0.2, 0.8],
 [0.0, 0.3, 0.7],
 [0.0, 0.4, 0.6],
 [0.0, 0.5, 0.5],
 [0.0, 0.6, 0.4],
 [0.0, 0.7, 0.3],
 [0.0, 0.8, 0.2],
 [0.0, 0.9, 0.1],
 [0.0, 1.0, 0.0],
 [0.1, 0.0, 0.9],
 [0.1, 0.1, 0.8],
 [0.1, 0.2, 0.7],
 [0.1, 0.3, 0.6],
 [0.1, 0.4, 0.5],
 [0.1, 0.5, 0.4],
 [0.1, 0.6, 0.3],
 [0.1, 0.7, 0.2],
 [0.1, 0.8, 0.1],
 [0.1, 0.9, 0.0],
 [0.2, 0.0, 0.8],
 [0.2, 0.1, 0.7],
 [0.2, 0.2, 0.6],
 [0.2, 0.3, 0.5],
 [0.2, 0.4, 0.4],
 [0.2, 0.5, 0.3],
 [0.2, 0.6, 0.2],
 [0.2, 0.7, 0.1],
 [0.2, 0.8, 0.0],
 [0.3, 0.0, 0.7],
 [0.3, 0.1, 0.6],
 [0.3, 0.2, 0.5],
 [0.3, 0.3, 0.4],
 [0.3, 0.4, 0.3],
 [0.3, 0.5, 0.2],
 [0.3, 0.6, 0.1],
 [0.3, 0.7, 0.0],
 [0.4, 0.0, 0.6],
 [0.4, 0.1, 0.5],
 [0.4, 0.2, 0.4],
 [0.4, 0.3, 0.3],
 [0.4, 0.4, 0.2],
 [0.4, 0.5, 0.1],
 [0.4, 0.6, 0.0],
 [0.5, 0.0, 0.5],
 [0.5, 0.1, 0.4],
 [0.5, 0.2, 0.3],
 [0.5, 0.3, 0.2],
 [0.5, 0.4, 0.1],
 [0.5, 0.5, 0.0],
 [0.6, 0.0, 0.4],
 [0.6, 0.1, 0.3],
 [0.6, 0.2, 0.2],
 [0.6, 0.3, 0.1],
 [0.6, 0.4, 0.0],
 [0.7, 0.0, 0.3],
 [0.7, 0.1, 0.2],
 [0.7, 0.2, 0.1],
 [0.7, 0.3, 0.0],
 [0.8, 0.0, 0.2],
 [0.8, 0.1, 0.1],
 [0.8, 0.2, 0.0],
 [0.9, 0.0, 0.1],
 [0.9, 0.1, 0.0],
 [1.0, 0.0, 0.0]]

你需要更精确,你想要所有可能的组合,包括
[0.7,0.2,0.1]
还是第三维度总是在减少,第一维度和第二维度总是在增加?如果第三维度达到零呢?抱歉没有澄清我的问题。我认为它最好有一些模式,就像你说的,第三维度应该总是减少,它可以达到0。所有可能的组合都可能是最好的。