All Questions
724 questions
-1
votes
1
answer
54
views
Generate and loop through pairs in a code block [duplicate]
I am trying to generate a list of unique pairs from two ranges. I then want to use this list of unique pairs as part of a URL in a loop to download a large batch of data.
I have managed to generate my ...
0
votes
1
answer
70
views
Creating a 'for' or 'if-else' selector for checking dynamically sized python List
I'm trying to mask 8752 images with transformers like this
from transformers import pipeline
from PIL import Image
import requests
import cv2
import numpy as np
from matplotlib import pyplot as plt
...
1
vote
2
answers
91
views
Looping if statement
I want to loop through an array with an if statement and only after it has looped through the entire array execute the else.
This is how i have my code now
for index, nameList in enumerate(checkedName)...
0
votes
0
answers
37
views
Finding the VIF of Standardized Variables in python
import numpy as np
import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
import seaborn as sns
sns.set()
from ...
0
votes
0
answers
30
views
How to get a third dimension in xarray from loop values?
I have a climatology data array for 41 years over the winter period (defined as November 1 - March 31). From this climatology Xarray DataArray (with over 6,000 days/values), I have grouped the days ...
0
votes
0
answers
27
views
How to populate a matrix assigning values based on placeholders?
I have a matrix populated with letters as placeholders. I need these letters to be substituted with integers ranging from 0 to 9. Each of these integers will correspond to one digit of a number formed ...
0
votes
0
answers
129
views
Loops - Why is my solution so much slower for hackerrank new year chaos?
I was doing the hackerrank "new year chaos" problem. Here is the description:
It is New Year's Day and people are in line for the Wonderland rollercoaster ride. Each person wears a sticker ...
0
votes
1
answer
250
views
How can I loop faster over an array using Cython?
I have an optics tool in which i need to calculate a set of complex amplitudes (i.e. wavefronts) for a range of time steps and wavelengths. So essentially I have two for loops and for each item I have ...
0
votes
2
answers
446
views
I am trying to find a way to act on characters in an array in Python
I am very new to coding and Python. I am trying to change characters in string elements of an array conditional on their adjacency to another character.
These characters are grouped into arrays based ...
0
votes
1
answer
132
views
Append elements to different lists based on if-else statements in python
I have been trying to create the following program in Python. However, I am getting frustrated with my program, and I have no idea what I should be doing! Specifically, I am having trouble appending ...
-1
votes
2
answers
54
views
Python String Comparisons, why does x for x not work with list of lists
I am trying to get a value out of a list of array of strings based on another value in the same array.
zone = [x for x in zoneList if (x[2] == usageRow[2])][1]
This is not part of the code, just a ...
0
votes
2
answers
47
views
How to add two numpy arrays by comparing element size?
I have two numpy arrays in python:
a = np.array([1, 7, 2, 10, 5])
b = np.array([1, 5, 3, 4, 1])
I want to add these two arrays such that the final array has sum elements only if the element of array ...
0
votes
4
answers
103
views
What am I doing wrong in this Pascal's triangle generator?
I am trying to print Pascal's triangle using Python. I am using nested lists and loops. It works something like this. For n = 2 it should print:
1
1 1
1 2 1
This is my code:
n = int(input("...
0
votes
0
answers
52
views
Iterating through 3D numpy arrays
I am trying to write a memory efficient code for iterating through 2 three-dimensional numpy arrays. Consider the following example:
First array is 3 dimensional for global NDVI (LAT, LON, TIME)
...
1
vote
0
answers
80
views
array populated from a loop gets overwritten
I have the following code - I am parsing a dataframe and creating lists from subsets of data found in the dataframe. I then transform the lists into arrays as I'd like to do further treatment (later ...