for-loop

php chunk arrays into batches

走远了吗. 提交于 2020-01-30 12:57:09
问题 I have an array with say 400 (but could be anything) names i want to send to an API, but the API only receives a max of 200 requests per time, how do i chunk my array so that for every 200th item, i perform an action? Here's what i have so far, rather than making my API request, i'm just trying to output the array's to the page. <?php for ($i = 0; $i <= $smsListLimit; $i++) { if ($i <= 199) { array_push($newarray, $smsList[$i]); if ($i == 199) { echo “ < pre > “; var_dump($newarray); echo “ <

For in loop over dict gives TypeError: string indices must be integers

戏子无情 提交于 2020-01-30 11:29:04
问题 I have a dict with 11 items in it, here's a scree shot from Spyder variable explorer: def buildDF(result_set): master_dm = [] for p in result_set: rows = p['reports'] master_dm.append(rows) return(master_dm) sessions1DF = buildDF(sessions1) TypeError: string indices must be integers When I view sessions1 I can see that it's a dict with the 11 items per the screen above. Double clicking on one of the items shows the reports inside each item: Why am I getting this error and how can I build a

Matlab: Graphing Multiple Vertical Bar Plots

让人想犯罪 __ 提交于 2020-01-30 11:05:29
问题 In my plot, I'm trying to display the average delay time from 6 airports for each of the 5 dates. Here is the code I have so far: F = dataset('xlsfile','Lab2_Delta'); DATES = {'11/26/2013','11/27/2013','11/28/20113','11/29/2013','11/30/2013'}; ORIGINS = {'CVG','ORD','ATL','LAX','MIA','DFW'}; for Index = 1:6 for Index2 = 1:5 Origin_Index = find(strcmp(F.Origin,ORIGINS(Index))); Date_Index = find(strcmp(F.Date,DATES(Index2))); Temps(Index2,Index) = mean(F.Delay(Date_Index)); end end bar(1:5

Matlab: Graphing Multiple Vertical Bar Plots

守給你的承諾、 提交于 2020-01-30 11:04:13
问题 In my plot, I'm trying to display the average delay time from 6 airports for each of the 5 dates. Here is the code I have so far: F = dataset('xlsfile','Lab2_Delta'); DATES = {'11/26/2013','11/27/2013','11/28/20113','11/29/2013','11/30/2013'}; ORIGINS = {'CVG','ORD','ATL','LAX','MIA','DFW'}; for Index = 1:6 for Index2 = 1:5 Origin_Index = find(strcmp(F.Origin,ORIGINS(Index))); Date_Index = find(strcmp(F.Date,DATES(Index2))); Temps(Index2,Index) = mean(F.Delay(Date_Index)); end end bar(1:5

Push associative array from for-loop in php

故事扮演 提交于 2020-01-30 05:14:23
问题 The for loop is supposed to loop 10 times. When I just print the $fname , $lname and $email I am getting the 10 data (Working fine) But I need to store those value in an associative array. $assocDataArray = array(); foreach ($data as $key => $value) { foreach ($value['emails'] as $lead) { $fname = $lead['first_name']; $lname = $lead['last_name']; $email = $lead['value']; //put objects in array $assocDataArray += [ "First Name" => $fname ]; $assocDataArray += [ "Last Name" => $lname ];

Why isn't my code printing like it should?

点点圈 提交于 2020-01-30 04:38:30
问题 I'm trying to create a for in Clojure. I'm following the cheats sheet from the Clojure site. e.g: (take 100 (for [x (range 100000000) y (range 1000000) :while (< y x)] [x y])) I'm trying to create my own for which should print "Hello World" 100 times. (take 100 (for [a (range 100) :while (< a 100)] (println "Hello World") ) ) For some reason it's not printing Hello World 100 times. Why not? 回答1: The most important thing you need to be aware of, is that sequences in Clojure are lazy. That

how to use “for loop” and “write.csv” at the same time?

≡放荡痞女 提交于 2020-01-29 16:57:54
问题 I have an array. It has lat,lon,time,and value. Time starts from 1 to 300. Here is part of array for time=1. myarray[,,1] lon lat -124.5 -123.5 -122.5 -121.5 -120.5 -119.5 -118.5 31.5 0 0 0 0 0 0 32.5 0 0 0 0 0 0 33.5 0 0 0 0 0 0 34.5 0 0 0 0 0 0 35.5 0 0 0 0 0 0 36.5 0 0 0 768.1 0 126.2 37.5 0 0 0.2 0 811 212.1 38.5 0 0 3055 0 243.9 243.7 39.5 0 0 1.5 0.1 3 0 40.5 0.1 16.8 4.3 0.5 2.1 0 41.5 0.2 398.6 0.4 1.2 1.6 0 42.5 0 0.1 0.9 0.1 0.7 0 I want to use "write.csv" and "for loop" at the same

how to use “for loop” and “write.csv” at the same time?

痞子三分冷 提交于 2020-01-29 16:57:09
问题 I have an array. It has lat,lon,time,and value. Time starts from 1 to 300. Here is part of array for time=1. myarray[,,1] lon lat -124.5 -123.5 -122.5 -121.5 -120.5 -119.5 -118.5 31.5 0 0 0 0 0 0 32.5 0 0 0 0 0 0 33.5 0 0 0 0 0 0 34.5 0 0 0 0 0 0 35.5 0 0 0 0 0 0 36.5 0 0 0 768.1 0 126.2 37.5 0 0 0.2 0 811 212.1 38.5 0 0 3055 0 243.9 243.7 39.5 0 0 1.5 0.1 3 0 40.5 0.1 16.8 4.3 0.5 2.1 0 41.5 0.2 398.6 0.4 1.2 1.6 0 42.5 0 0.1 0.9 0.1 0.7 0 I want to use "write.csv" and "for loop" at the same

for loop terminating early when comparing to Integer.MAX_VALUE and using System.out.println

余生颓废 提交于 2020-01-29 12:04:48
问题 When I run this class the for loop seems to terminate early class Test { public static void main(String[] args) { int result = 0; int end = Integer.MAX_VALUE; int i; for (i = 1; i <= end; i += 2) { System.out.println(i); } System.out.println("End:" + i); } } Output is: 1 3 5 ... 31173 31175 End:31177 Why does it end there? Interestingly if I removed the System.out.println(i) in the for loop, the output would be End:-2147483647 . Obviously the value in i has wrapped round . The Java version I

Set value for all rows in a datatable without for loop

≡放荡痞女 提交于 2020-01-27 07:42:12
问题 I'm trying to set the same value for all rows for a single column in a datatable without using for loop. Can anyone suggest any faster methods to achieve the same. 回答1: Not unless you count foreach . One way or another, you'll need to loop. If you use the DataTable version, the fastest approach is to use the DataColumn accessor, i.e. var col = table.Columns["Foo"]; foreach(var row in table.Rows) row[col] = value; As an alternative : since this presumably relates to a database, write the TSQL