for-loop

Why are for-loops much slower than broadcasting

Why are for-loops much slower than broadcasting Question: Comparing two chunks of code for a simple matrix operation, the one with a nested for loop is much slower. I wonder: what is the underlying reason for this? This loop tuns for 2.5 seconds: m = np.zeros((800,8000)) for i in range(0,800): for j in range(0,8000): m[i,j] …

Total answers: 1

Python: How to get index from an Array of JSON?

Python: How to get index from an Array of JSON? Question: So, I was able to answer my question before on how to get the value of a JSON from an array of JSON. But now I’m trying to convert it in Python(for selenium). Here is the Array of JSON: [ { "id": 3328367679, "inbox_id": …

Total answers: 2

How to iterate over a list of lists and update one of the sublists with content from previous iterations under certain conditions?

How to iterate over a list of lists and update one of the sublists with content from previous iterations under certain conditions? Question: prev_names_elements = [] # keep track of names from previous iterations for idx, i in enumerate(["1", "2", "3", "4"]): if (i == "1"): i_list = [[‘Luciana’, ‘MarĂ­a’, ‘Lucy’], [‘jugando’], [], [‘2023_-_03_-_07(19:00 pm_—_23:59 …

Total answers: 1

how to loop through a list of integers

how to loop through a list of integers Question: I’m trying to loop through a list of integers by using a for loop. However, we know that in python, int is not iterable. So I’m wondering if there’s any ways I can store integers in another way so that I can loop through the integers? …

Total answers: 5

How do I search for a specific value in a 2d array in Python?

How do I search for a specific value in a 2d array in Python? Question: I want to iterate through 2 specific rows of a 2d array to find a specific value, but I am unable to do so. In my program, I have read in a 2d array from a text file using the …

Total answers: 3

Is there any solution to substitute loops in Numpy?

Is there any solution to substitute loops in Numpy? Question: I now have a simple loop for i in range(4): Q[i, x[i] : x[i] + 2] = 1 / 2 where Q = np.zeros([4,4]) and x = [0,1,0,1]. The goal of this question is to obtain the result of this loop without using loop but …

Total answers: 1

how to loop over a list of dataframes and change specific values

how to loop over a list of dataframes and change specific values Question: I have a list of dataframes. Each dataframe of the list has following format: (screenshot from spyder) On this list of dataframes, I perform several tasks. For example, I want to change the name of "specA" to "Homo sapiens" in all of …

Total answers: 1

Using For Loop and If Statement Together

Using For Loop and If Statement Together Question: I am trying to get a function, "mock_function", to iterate through the array, "x", and either square or cube its elements, depending on if the element is greater than 5 or not. I need the output to be an array as well, containing the elements squared or …

Total answers: 2