how to generate all possible combinations of a 14x10 matrix containing only 1's and 0's

前端 未结 11 1007
悲&欢浪女
悲&欢浪女 2021-01-23 23:32

I\'m working on a problem and one solution would require an input of every 14x10 matrix that is possible to be made up of 1\'s and 0\'s... how can I generate these so that I can

11条回答
  •  鱼传尺愫
    2021-01-24 00:15

    The actual implementation depends heavily on how you want to represent matrices… But assuming the matrix can be represented by a 14 * 10 = 140 element list:

    from itertools import product
    for matrix in product([0, 1], repeat=140):
        # ... do stuff with the matrix ...
    

    Of course, as other posters have noted, this probably isn't what you want to do… But if it really is what you want to do, that's the best code (given your requirements) to do it.

提交回复
热议问题