简体   繁体   English

矩阵中第一行的元素,每行取一个元素,并与行的所有元素进行迭代

[英]elements from first row in a matrix operated with one element taken from each row, iterating with all the elements of rows

Consider a 2D list in python. 考虑一下python中的2D列表。 Taking the first list of given 2D list, I want to do XOR operation of each element from the first list with one element each from subsequent lists so that I have n-1 elements operated with that one element. 以给定的2D列表的第一个列表为例,我想对第一个列表中的每个元素与后续列表中的每个元素进行XOR操作,这样我就可以对该元素进行n-1个元素的操作。

Example - list = [[0,1], [0,1,2,3], [0,1,2]] 示例-列表= [[0,1],[0,1,2,3],[0,1,2]]

combinations formed will be - 0^0^0, 0^0^1, 0^0^2, 0^1^0, 0^1^1, 0^1^2, 0^2^0, 0^2^1, 0^2^2, 0^3^0, 0^3^1, 0^3^2, 1^0^0, 1^0^1, 1^0^2, 1^1^0, 1^1^1, 1^1^2, 1^2^0, 1^2^1, 1^2^2, 1^3^0, 1^3^1, 1^3^2 形成的组合将是-0 ^ 0 ^ 0、0 ^ 0 ^ 1、0 ^ 0 ^ 2、0 ^ 1 ^ 0、0 ^ 1 ^ 1、0 ^ 1 ^ 2、0 ^ 2 ^ 0、0 ^ 2 ^ 1、0 ^ 2 ^ 2、0 ^ 3 ^ 0、0 ^ 3 ^ 1、0 ^ 3 ^ 2、1 ^ 0 ^ 0、1 ^ 0 ^ 1、1 ^ 0 ^ 2、1 ^ 1 ^ 0 ,1 ^ 1 ^ 1、1 ^ 1 ^ 2、1 ^ 2 ^ 0、1 ^ 2 ^ 1、1 ^ 2 ^ 2、1 ^ 3 ^ 0、1 ^ 3 ^ 1、1 ^ 3 ^ 2

condition - The size of any of the list or sublists is not predefined 条件-任何列表或子列表的大小均未预定义

for_the_product = [[0,1], [0,1,2,3], [0,1,2]]
for one_tuple in itertools.product(*for_the_product):
    do_something_with(one_tuple)

More explanation in the python documentation . python文档中有更多解释 The * gives each elements of your initial list ( for_the_product in my code) as an argument to the product function. *给出了初始列表的每个元素(在我的代码中为for_the_product ),作为product函数的参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从每一行中找到最小值(如果一行中有很多最小值保留第一个)并将矩阵的其他元素替换为 0? - How to find a minimum from every rows(if there are many minimums in a row keep the first one ) and replace else elements of matrix with 0? 仅在所有元素为 0 的矩阵的第一行和第一列中添加元素 - Adding elements only in first row and first column of a matrix with all elements 0 如何从该行的所有元素中减去2D张量每一行的max元素 - How do I subtract the max element of each row of a 2D tensor from all elements of that row 计算每行中等于每行中第一个元素的元素数 - Count number of elements in each row equal to the first element in each row 给定每一行对应的索引,从矩阵中获取对应的元素 - Given the indexes corresponding to each row, get the corresponding elements from a matrix 通过从 array1 中的所有第一列与 array2 中的所有行查找匹配元素来检索行元素 - Retrieve row elements by finding matching elements from all first columns in array1 with all rows from array2 Python从矩阵的每一行中减去第一个元素 - Python subtract first element from each respective row of matrix 从所有其他行中减去每一行并在 python 中查看矩阵 - subtract each row from all other rows and view as matrix in python CSV文件的第一行是一个字符串的列表,而其余行是Python中的元素列表 - First row from a CSV file is a list of one string while the remaining rows are list of elements in Python 用列表中的元素替换包含某个字符的所有行,迭代输入中每一行的每个元素 - Replace all lines containing a certain character with elements from a list, iterating through each element for each line in input
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM