在python中获取所有可能的单字节 [英] get all possible single bytes in python

查看:71
本文介绍了在python中获取所有可能的单字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to generate all possible bytes to test for a machine learning algorithm (8-3-8 mural network encoder). is there a way to do this in python without having 8 loops?

排列可以帮助吗?

d希望采用一种优雅的方法来执行此操作,但我将尽我所能。

I'd prefer an elegant way to do this, but I'll take what I can get at the moment.

所需的输出:

[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]


推荐答案

是的,有 itertools。产品

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),

[...]

 (1, 1, 1, 1, 1, 1, 1, 0),
 (1, 1, 1, 1, 1, 1, 1, 1)]

这篇关于在python中获取所有可能的单字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆