获取python中所有可能的单个字节

kma*_*ace 3 python byte combinations

我正在尝试生成所有可能的字节来测试机器学习算法(8-3-8壁画网络编码器).有没有办法在没有8个循环的python中做到这一点?

排列有帮助吗?

我更喜欢优雅的方式来做这件事,但我会采取我目前所能得到的.

期望的输出:

[0,0,0,0,0,0,0,0]
[0,0,0,0,0,0,0,1]
[0,0,0,0,0,0,1,0]
[0,0,0,0,0,0,1,1]
[0,0,0,0,0,1,0,0]
[0,0,0,0,0,1,0,1]
.
.
.
[1,1,1,1,1,1,1,1]
Run Code Online (Sandbox Code Playgroud)

Ada*_*eng 11

是的,有,itertools.product:

import itertools


itertools.product([0, 1], repeat=8)
>>> list(itertools.product([0, 1], repeat=8))
[(0, 0, 0, 0, 0, 0, 0, 0),
 (0, 0, 0, 0, 0, 0, 0, 1),
Run Code Online (Sandbox Code Playgroud)

[...]

 (1, 1, 1, 1, 1, 1, 1, 0),
 (1, 1, 1, 1, 1, 1, 1, 1)]
Run Code Online (Sandbox Code Playgroud)


Joh*_*ooy 6

[[x>>b&1 for b in range(8)] for x in range(256)]
Run Code Online (Sandbox Code Playgroud)