All Questions
209 questions
1
vote
0
answers
94
views
Python Iterating over Numpy Tile and for-loops
Goal: Here is a sample of a dataset that has "ID", "PHASENAME", "CDAYS", "MULTI_FACTOR", "DAY_COUNTER", and "DAILY_LABOR_PERCENT". I was ...
-1
votes
2
answers
112
views
Python coding question regarding "stacking arrays to an array" [closed]
I have a simple Python coding question regarding "stacking array inside array". Here, I have several arrays as follows:
a1 = np.array([[1,1,1],[1,1,1],[1,1,1]])
a2 = np.array([[2,2,2],[2,2,...
0
votes
2
answers
65
views
Looping over first two indices in 4-Dimensional Array?
I have an np.array that has dimensions 478,533,3,3 (variable is titled "window," generated with NumPy stride tricks sliding window from a larger 2D array). The 478x535 portion of the array ...
1
vote
1
answer
54
views
indexing a numpy array by an array of indices in a loop
i have a vector i want to shuffle in batches.
the idea i came up with is to reshape it into 2D array with each row as a batch.
then i shuffle each row on its own.
this is toy example of the approach
# ...
1
vote
1
answer
77
views
How to map elements in 2d numpy array without using for-loop?
I want to reorganize the elements in a 2d numpy array based on data stored in a list of lists.
The below (simplified) minimum code example does exactly what I intend to do, but by using a rather slow ...
0
votes
1
answer
131
views
Appending to a numpy array in for loop
I'm trying to create a Monte Carlo simulation to simulate future stock prices using Numpy arrays.
My current approach is: create a For Loop which fills an array, stock_price_array, with simulated ...
-1
votes
1
answer
107
views
how i can calculate the adjacent and opposite of this matrix?
i have this matrix
Matrix = [[0., 15., 19., 18., 17.],
[15., 0., 14., 12., 23.],
[19., 14., 0., 14., 21.],
[18., 12., 14., 0., 14.],
[17., 23., 21., 14., 0.]]
and i cut it to ...
0
votes
1
answer
24
views
How can i create 2 for loops to replace values in Numpy array?
How can i use two for loops to replace the values in x with the row number, starting at 1, so it should be [[1,1,1,1,1],[2,2,2,2,2] … [5,5,5,5,5]]
x=np.ones((5,5))
print(x)
Thanks
1
vote
3
answers
838
views
Multiplying array of vectors by matrix without for loop
I have a 2 x 2 numpy.array() matrix, and an array N x 2 X, containing N 2-dimensional vectors.
I want to multiply each vector in X by the 2 x 2 matrix. Below I use a for loop, but I am sure there is a ...
0
votes
1
answer
232
views
Replace the values of a column of an array in a for loop Python
I have a 3D array of zeros and I would like, using a for loop, to replace the elements of the second and third column.
In matlab i created a zeros matrix and fill it, but in python i don't understand ...
0
votes
1
answer
30
views
Interleaving IDs of groups, with IDs coming from 2 separate arrays, defining size of groups
The problem
I have 2 different functions, named update() and reset().
I am referring to these functions as 'IDs' in the title of the ticket.
They apply successively to groups of contiguous rows from ...
-1
votes
1
answer
59
views
Creating a day of year column overriding the leap day in a leap year
I have a large database of climate variables - daily values of temp, humidity etc. I have a timestamp column %Y%m%d. I have removed leap days, as I need uniform 365 days for each of my years. I want ...
-1
votes
1
answer
53
views
Edit function to work for arrays instead of lists
I have a function that does the following:
Takes uses the list as an input
Computes the sum of the list
Appends the output (the sum) to the input list
Runs itself again (this time with a list of N + ...
1
vote
1
answer
142
views
How do I sum the different values of an array corresponding with the values of a different array? [duplicate]
I am trying to sum the different values of an array, a, that corresponds with the values of b.
a = np.array([2,3,4,5,6,7,8,9,10])
b = np.array([1,1,1,2,3,4,5,5,6])
For example, array b has 3 elements ...
0
votes
0
answers
81
views
Using pure numpy instead of multiple nested for loops that include a calculation with changing values
The following function uses nested for loops that include a calculation used to populate a numpy array:
def foo():
# Initializing variables
xrange = 2
yrange = 2
t_array = np.random.randint(1, ...