如何制作一个由 0 和 1 值组成的 n x 2^n 矩阵,其中所有列都不同?例如,如果 n = 2 那将是
0011
0101 .
而且我可以使用 itertools 生成所有可能的元组。
list(itertools.product([0,1],repeat = 2))
但是我如何使这些列成为矩阵的列?
最佳答案
只需将 np.matrix 应用于您的结果:
>>> np.matrix(list(itertools.product([0,1],repeat = 2)))
matrix([[0, 0],
[0, 1],
[1, 0],
[1, 1]])
关于python - 用每个可能的列创建一个矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20529167/