flatten

Sum of 2 different 2d arrays

风格不统一 提交于 2020-12-27 03:03:30
问题 I need help writing a method to find out a sum of 2 different sized 2d arrays. public static int[][] summary(int[][] tab1, int[][] tab2, int x) { int[][] finalTab = new int[4][5]; // I took sizes of bigger one if (x < 0) { for (int i = 0; i < finalTab.length - 1; i++) { for (int j = 0; j < finalTab[i].length - 1; j++) { finalTab[i][j] = tab1[i][j] + tab2[i][j]; if (tab1[i][j] == 0) { finalTab[i][j] = tab2[i][j]; } } } for (int i = 0; i < finalTab.length; i++) { for (int j = 0; j < finalTab[i]

Sum of 2 different 2d arrays

别来无恙 提交于 2020-12-27 03:03:24
问题 I need help writing a method to find out a sum of 2 different sized 2d arrays. public static int[][] summary(int[][] tab1, int[][] tab2, int x) { int[][] finalTab = new int[4][5]; // I took sizes of bigger one if (x < 0) { for (int i = 0; i < finalTab.length - 1; i++) { for (int j = 0; j < finalTab[i].length - 1; j++) { finalTab[i][j] = tab1[i][j] + tab2[i][j]; if (tab1[i][j] == 0) { finalTab[i][j] = tab2[i][j]; } } } for (int i = 0; i < finalTab.length; i++) { for (int j = 0; j < finalTab[i]

R (purrr) flatten list of named lists to list and keep names

妖精的绣舞 提交于 2020-12-26 07:39:27
问题 Maybe I'm missing something obvious but trying to flatten a list of named lists of named lists in R (may even be more nested) into eventually one flat list. purrr and rlist seem to have tools for that. How can I achieve that names of sublists become name precrypts of flattened result list, e.g. list1.blist.a in purrr ? My actual list is more deeply nested with varying number of levels and repeating names on different levels. In the end I perform purrr::map_df(final_list, bind_rows) and this

How to split strings inside a list by given delimiter and flatten the sub-strings lists

丶灬走出姿态 提交于 2020-12-26 04:53:33
问题 I have a python script with this list: blocks = [ "item-1", "item-2", "item-3.0;item-3.1;item-3.2" ] I have tried this: for (i, block) in enumerate(blocks): if ";" in block: [blocks.insert(i, c) for c in block.split(";")] else: blocks.insert(i, block) To get this: blocks = [ "item-1", "item-2", "item-3.0", "item-3.1", "item-3.2" ] Unfortunately my code keeps overwriting the the elements in the list, and I'm left with this: blocks = [ "item-1", "item-2", "item-3.2" ] How can I modify the

Flatten complex directory structure in Python

余生颓废 提交于 2020-12-08 07:06:31
问题 I want to move files from a complex directory structure to just one place. For example i have this deep hierarchy: foo/ foo2/ 1.jpg 2.jpg ... I want it to be: 1.jpg 2.jpg ... My current solution: def move(destination): for_removal = os.path.join(destination, '\\') is_in_parent = lambda x: x.find(for_removal) > -1 with directory(destination): files_to_move = filter(is_in_parent, glob_recursive(path='.')) for file in files_to_move: shutil.move(file, destination) Definitions: directory and glob

Flatten complex directory structure in Python

一曲冷凌霜 提交于 2020-12-08 07:05:40
问题 I want to move files from a complex directory structure to just one place. For example i have this deep hierarchy: foo/ foo2/ 1.jpg 2.jpg ... I want it to be: 1.jpg 2.jpg ... My current solution: def move(destination): for_removal = os.path.join(destination, '\\') is_in_parent = lambda x: x.find(for_removal) > -1 with directory(destination): files_to_move = filter(is_in_parent, glob_recursive(path='.')) for file in files_to_move: shutil.move(file, destination) Definitions: directory and glob