iteration

Apache POI - JAVA - iterating over columns in excel

夙愿已清 提交于 2020-01-02 07:23:21
问题 new to java here. I'm working on a code that reads excel files (looking at cells in columns) and then writes something that looks like the following tables: I have an excel file that looks like this: col1 col2 col3 col4 ----------------------------- row1 | 2,3,1 _ 1 w row2 | 3,2,7 _ 2 x row3 | _ _ 3 y row4 | 4,9 _ 4 z I'm writing some values (using XLWT) in column 2 that look like this: col1 col2 col3 col4 ----------------------------- row1 | 2,3,1 x,y,w 1 w row2 | 3,2,7 y,x 2 x row3 | _ _ 3

Gather image file paths Recursively in PHP

╄→尐↘猪︶ㄣ 提交于 2020-01-02 05:31:12
问题 I am working on a pretty large PHP class that does a lot of stuff with Image Optimization from the Command line, you basically pass the program an Image path or a Folder path that has multiple images inside of it. It then runs the files through up to 5 other command line programs that optimize images. Below is part of a loop that gathers the images paths, if the path is a Folder instead of an image path, it will iterate over all the images in the folder and add them to the image array. So far

How do you iterate over all configurations of m variables belonging to the same domain of size n?

孤人 提交于 2020-01-02 05:27:12
问题 EDIT: My solution is added to the end of the question. Thanks for the hint. I'll just go with an example. Suppose I have an array with length n : arr = { 1, 4, 8, 2, 5, ... } If I want to traverse all combinations of TWO elements I would write: for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { // do something with arr[i] and arr[j] } } I If I want to traverse all configurations of THREE elements I would simply add another layer of for iteration: for (int i = 0; i < n; i++) { for

Numpy: Beginner nditer

Deadly 提交于 2020-01-02 02:12:06
问题 I am trying to learn nditer for possible use in speeding up my application. Here, i try to make a facetious reshape program that will take a size 20 array and reshape it to a 5x4 array: myArray = np.arange(20) def fi_by_fo_100(array): offset = np.array([0, 4, 8, 12, 16]) it = np.nditer([offset, None], flags=['reduce_ok'], op_flags=[['readonly'], ['readwrite','allocate']], op_axes=[None, [0,1,-1]], itershape=(-1, 4, offset.size)) while not it.finished: indices = np.arange(it[0],(it[0]+4),

Is there a way to have parallel for-each loops?

微笑、不失礼 提交于 2020-01-02 01:05:07
问题 Let's say I have 2 lists in Python and I want to loop through each one in parallel - e.g. do something with element 1 for both lists, do something with element 2 for both lists... I know that I can do this by using an index: for listIndex in range(len(list1)): doSomething(list1[listIndex]) doSomething(list2[listIndex]) But is there a way to do this more intuitively, with a foreach loop? Something like for list1Value in list1, list2Value in list2 ...? I've currently run into this situation in

How to calculate iteratively the running weighted average so that last values to weight most?

南楼画角 提交于 2020-01-01 08:28:00
问题 I want to implement an iterative algorithm, which calculates weighted average. The specific weight law does not matter, but it should be close to 1 for the newest values and close to 0 to the oldest. The algorithm should be iterative. i.e. it should not remember all previous values. It should know only one newest value and any aggregative information about past, like previous values of the average, sums, counts etc. Is it possible? For example, the following algorithm can be: void iterate

Read multiple jQuery.val() into array

徘徊边缘 提交于 2019-12-31 19:14:06
问题 I have some code that looks like this that works just fine: var info = []; for (i = 0; i < 10; i++) { info[i] = $('#info_' + i).val(); } The problem is that this pattern is very common in my application with some minor variations. What i would like to do is to make this into a oneliner something like this where info becomes an array: var info = $('[id^="info_"]').each().val(); 回答1: Found a solution thanks to Dogbert. All that was missing in his example was the .get() Here is the solution i

Python + MongoDB - Cursor iteration too slow

萝らか妹 提交于 2019-12-31 14:34:13
问题 I'm actually working in a search engine project. We are working with python + mongoDb. I'm having the following problem: I have a pymongo cursor after excecuting a find() command to the mongo db. The pymongo cursor have around 20k results. I have noticed that the iteration over the pymongo cursor is really slow compared with a normal iteration over for example a list of the same size. I did a little benchmark: -iteration over a list of 20k strings: 0.001492 seconds -iteration over a pymongo

React - JSX syntax issue, and how to iterate with map and display items on newlines

蹲街弑〆低调 提交于 2019-12-31 07:31:16
问题 I'm a React noob and making a ToDo list style Recipe List app. I have a functional component, Item.js, and I am using JSX and the map function to iterate through each recipe item and display them. I want each recipe item to appear on a new line, but when I use .map to iterate through them React puts the entire list of recipe items into one p tag instead of one p tag for each item. How can I iterate through the recipe items and display them on separate lines? Even if I try to display them as

React - JSX syntax issue, and how to iterate with map and display items on newlines

僤鯓⒐⒋嵵緔 提交于 2019-12-31 07:31:11
问题 I'm a React noob and making a ToDo list style Recipe List app. I have a functional component, Item.js, and I am using JSX and the map function to iterate through each recipe item and display them. I want each recipe item to appear on a new line, but when I use .map to iterate through them React puts the entire list of recipe items into one p tag instead of one p tag for each item. How can I iterate through the recipe items and display them on separate lines? Even if I try to display them as