loops

Play swift sound based on each duration of I time in array

北城余情 提交于 2021-01-29 20:43:51
问题 I want my swift code to call the playSound and play the sound based for the duration of each item in array playamount. So I want the user to play the sound for the first time for 10 seconds then play the sound starting at the beginning for 20 and then the same thing for 30 seconds. So the sound always starts at the beginning each time it is called. import UIKit; import AVFoundation class ViewController: UIViewController { var player: AVAudioPlayer? func playSound() { let url = Bundle

How to update multiple Numpy arrays in a loop

送分小仙女□ 提交于 2021-01-29 20:41:13
问题 I would like to update (prepend each one with additional elements) many numpy arrays in a loop, without having to repeat the code for each one. I tried creating a list of all the arrays and looping through the items in that list and updating each one, but that doesn't change the original array. import numpy as np arr01 = [1,2,3] arr02 = [4,5,6] arr99 = [7,8,9] print('initial arr01', arr01) arraylist = [arr01, arr02, arr99] for array in arraylist: array = np.concatenate((np.zeros(3, dtype=int)

Iteration over years to plot different group values as bar plot in pandas

依然范特西╮ 提交于 2021-01-29 20:30:45
问题 I have a dataframe that records number of observations at different locations for different years. I am trying to make a barplot where I can show the total number of observations at different locations for different years. For each location, I want the total observations, for different years to be shown in different colors. My approach is to first make location groups and for each location group, calculate total observation. (I don't think I need to change the index to date - as I am grouping

Running out of memory on python product iteration chain

妖精的绣舞 提交于 2021-01-29 19:52:48
问题 I am trying to build a list of possible string combinations to then iterate against it. I am running out of memory executing the below line, which I get because it's several billion lines. data = list(map(''.join,chain.from_iterable(product(string.digits+string.ascii_lowercase+'/',repeat = i) for i in range(0,7)))) So I think, rather than creating this massive iterable list, I create it and execute against it in waves with some kind of "holding string" that I save to memory and can restart

Assign event number based on Date of occurece in R dataframe

℡╲_俬逩灬. 提交于 2021-01-29 19:50:40
问题 How to assign an event number based on their date of occurrence satisfying the following conditions. If the event occurs for at least 3 consecutive days ( or more ) assign event number e1 and so on and mutate (join) with the original data frame. If the occurrence is not for continuous 3 days, assign NA and mutate with the original data frame. In time series dts how can I achieve it. The output data frame would be like dts_output (done manually). dts<-structure(list(Date = structure(c(16442,

How can I iterate through two dataframes and assign a new values based on compared columns?

筅森魡賤 提交于 2021-01-29 19:27:15
问题 I have two different dataframes: A, B. The column Event has similar data that I'm using to compare the two dataframes. I want to give Dataframe A a new column, dfA.newContext#. In order to do this, I'll need to use the Event column. I want to iterate through Dataframe A to find a match for Event and assign the dfB.context# to dfA.newContext# I think a loop would be the best way since I have a few conditions that I need to check. This might be asking a bit much but I'm really stuck.. I want to

How to prevent non-numeric input in C & ask user input again

做~自己de王妃 提交于 2021-01-29 19:11:21
问题 Actually, I can easily found a similar question in Google, but it still can not solve my question. How to prevent non-numeric input in C? The upper-link is like a similar case. Here is my code #include <stdio.h> int main() { int n; printf("Enter 1 or 2?\n"); scanf("%d", &n); while(n != 1 && n != 2) { printf("Please do not enter other characters\n"); printf("Enter 1 or 2?\n"); scanf("%d", &n); } } I hope if users enter other numbers(e.g. 1, 45, 656), characters (e.g. a, f, u, e), or string(e.g

JS/Cypress.io: How to iterate over 2 corresponding sets of data

让人想犯罪 __ 提交于 2021-01-29 18:31:20
问题 JS/Cypress.io: How to iterate over 2 corresponding sets of data This is what I have currently and it works, but I want to make it more DRY (do not repeat yourself): Using Cypress.io: var states1 = [ "NE", "MO", "KS", "IA", "OK", "OR", "WA", "AZ", "NM", "NC", "SC", "GA", "FL" ]; cy.get('[data-popup-text="26% to 50% of People"]').within(() => { cy.wrap(states1).each(state => { cy.get(`[data-state="${state}"]`).trigger("mouseover", { force: true }); cy.get(`[data-state="${state}"]`).click({

For loop works perfectly fine, but once I make a function out of it, it suddenly doesn't give the right results in R

爷,独闯天下 提交于 2021-01-29 17:37:52
问题 I have the following for-loop which does exactly what I want: for (t in 3:20){ XX <- c(rep(0,22)) for (k in (1:(t-2))){ XX[k] <- (theta^(k-1) * (P[t-k] - P[t-k-1])) } X[t] = (1-theta) * sum(XX) + theta^(t-1) P[t] <- D[t] + (0.7/0.3) * X[t] - 0.1*3^2*1*(20-t-1 + (1/0.3)) } However, once I make a function out of and use the function the results are suddenly wrong: BGJS <- function(theta){ for (t in 3:20){ XX <- c(rep(0,22)) for (k in (1:(t-2))){ XX[k] <- (theta^(k-1) * (P[t-k] - P[t-k-1])) } X

intersect polygons based on if conditions on column values

不问归期 提交于 2021-01-29 16:23:55
问题 I want to intersect polygons within a GeoDataFrame based on if conditions on column values. I made up the GeoDataFrame with "id", "yr" (year), "wk" (week). # import libraries import pandas as pd import geopandas as gpd import matplotlib.pyplot as plt # txt 2 polygon d = {'id': {0: 'a', 1: 'a', 2: 'a', 3: 'a', 4: 'a', 5: 'a', 6: 'a', 7: 'a', 8: 'a', 9: 'a', 10: 'b', 11: 'b', 12: 'b', 13: 'b', 14: 'b', 15: 'b', 16: 'b', 17: 'b', 18: 'b', 19: 'b', 20: 'c', 21: 'c', 22: 'c', 23: 'c', 24: 'c'},