Skip to main content
Filter by
Sorted by
Tagged with
0 votes
4 answers
241 views

I have two pandas dataframes: One assembled manually in Python, the other imported from a dashboard's .csv output. All columns in both dataframes are objects, and look like this: 2020 2021 2022 2023 0....
gorilla's user avatar
  • 47
5 votes
1 answer
303 views

My intuition when using Pandas is that, if you have to use df.apply, it would be more optimal to group all the apply operations into one call. This was further reinforced by me learning that NumPy ...
v0rtex's user avatar
  • 53
2 votes
0 answers
168 views

I am training a model using TensorFlow/Keras using TensorFlow 2.19.0/Keras 3.10.0. During training, I monitor nvidia-smi and top, and the system RAM and the GPU RAM increase during the training period....
CopyOfA's user avatar
  • 931
0 votes
1 answer
90 views

i would like to create a nested list of arbitrary depth (containing numerical values specifically) with uniform arbitrary lengths at each level and then compress it to a NumPy array of minimum ...
L8t Original's user avatar
3 votes
1 answer
208 views

I have difficulties from this: (aws-lambda-python-alpha): Failed to install numpy 2.3.0 with Python 3.11 or lower My Dockerfile: FROM public.ecr.aws/lambda/python:3.11 # Install RUN pip install '...
Flo's user avatar
  • 485
13 votes
2 answers
2k views

In this assignment I created the basic rect signal a[n] such that over the domain [-1000, 1000] it's 1 only at |n|<100, meaning it's an array (complex one with zero in the imaginary part) that ...
Nate3384's user avatar
  • 314
1 vote
1 answer
124 views

As the numpy docs describe for the object dtype, arrays created with the object dtype are simply references to an underlying data store like a python list. The tobytes() method on such an object ...
Dryden's user avatar
  • 118
3 votes
1 answer
240 views

It seems like the standard numpy.random.shuffle function shuffles (in place) only the first dimension / axis. I want a similar functionality for inner dimensions. Note that numpy.random.default_rng()....
omsrisagar's user avatar
1 vote
2 answers
106 views

I am trying to create a function which receives the transversal profile of a beam and outputs the transversal profile propagated by some distance. To exemplify the task, here is the profile of a ...
Henrique Guerra's user avatar
6 votes
1 answer
133 views

I'm trying to implement a block GMRES procedure (i.e., GMRES to solve Ax=b, but with b that is not a vector but a n x r matrix, where r << n). My goal is to have a first implementation in Python ...
Pierre Beaujean's user avatar
1 vote
1 answer
132 views

I am trying to compute business days using Numpy. I how ever found an inconsistency. import numpy as np # Count from 1st Jan 2023 to 31st Jan 2023 print("Jan: {0}".format(np.busday_count('...
M4X_'s user avatar
  • 583
2 votes
1 answer
104 views

I need to efficiently evaluate a bivariate spline on a B-spline basis. I have already calculated the knot positions and spline coefficients (independently of scipy classes/methods such as ...
Daniel Reese's user avatar
3 votes
3 answers
124 views

I'm very puzzled by the following behaviour of NumPy when assigning elements to an array using an array as indices. Here is a minimal working example: import numpy as np i = np.arange(2,4) a = np....
Daniel Reese's user avatar
1 vote
1 answer
86 views

This Python script: import numpy as np a = np.arange(12).reshape(6, 2) inf = np.array([2, 2]) sup = np.array([9, 9]) b = (inf < a) & (a < sup) r = a[b[:, 0] & b[:, 1]] creates a ...
Paul Jurczak's user avatar
  • 8,630
0 votes
2 answers
159 views

I have a python code that calculates a function F(X), where both F and X are arrays of the same shape. F(X) uses another function called from a package that only accepts a scalar as an argument, but I ...
Dennis Fr's user avatar
0 votes
1 answer
98 views

I was trying to mimic the result of a simple Tensorflow/Keras Dense layer with NumPy (forward pass only) and I was surprised not to have the exact same result. A dense layer output is just the product ...
el_grezeq's user avatar
  • 187
3 votes
2 answers
221 views

I recently learned about the downsides of using numpy.random.seed(seed). Some internal file can modify the seed.I read an online article that suggested I use np.random.default_rng(). But I am not sure ...
desert_ranger's user avatar
2 votes
3 answers
94 views

I have a dataset of binned events, corresponding to a cartesian coordinate set [[ 0. 0. 0. 0. 0. 0. 2. 5. 2. 3. 3. 0. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0. 4. 10. 9. 7. 10. 6. ...
David K.'s user avatar
  • 529
0 votes
0 answers
75 views

I installed GPflow and just tried to import it with ipython. But, I got an error like below. --------------------------------------------------------------------------- TypeError ...
sadradio's user avatar
9 votes
1 answer
314 views

Aim I am trying to generate random signals with the following two properties: The values should be approximately log-normally distributed (any long-tailed distribution bounded form below with non-...
Paul Brodersen's user avatar
1 vote
1 answer
174 views

I would like to calculate the lifetime of the particles from the extrapolated curve below, I know that lifetime is 1/decay constant but I get values for the decay constant that dont make sense. import ...
dutchrunner's user avatar
4 votes
3 answers
168 views

I'm trying to perform an element-wise addition between a 2D NumPy array and a 1D array (like adding a row vector to each row of a matrix), but I'm running into a broadcasting error. import numpy as np ...
Mr. Thomson's user avatar
0 votes
0 answers
99 views

I'm currently working on a model similar to DeepLOB, using high-frequency tick-level financial data. Due to the massive volume and the need to structure the data into time series format, it's ...
ZaixinDong's user avatar
0 votes
1 answer
114 views

I have a dataframe df, I want to do the following: run two stats tests on all the numeric columns (column_1 to column_84) to compare if there is a statistical difference between Types X, Y and Z The ...
RayX500's user avatar
  • 319
-3 votes
1 answer
78 views

I have written this code: df.loc[df['Profile Name'] == 'karladdo201', 'Duration'].astype('timedelta64[s]').sum() and get this value: Timedelta('8 days 12:02:45') How do I get a values similar or in ...
righthere's user avatar
3 votes
1 answer
59 views

I define an array of 4 corners import numpy as np class Corner(): centres = np.zeros((3,2)) id=0 corners=np.empty((4)).astype(Corner) for i in range(4): corner=Corner() corner.id = ...
user1069353's user avatar
0 votes
2 answers
281 views

Everytime, I want to access the documentation of libraries that I need for my project, I have to go to their website. Python has the excellent utility called pydoc, but I can only access the ...
ksinkar's user avatar
  • 306
1 vote
1 answer
108 views

I am seeing below error with numpy v2.0.2. numpy being used is locally built with openblas v0.3.29, but during a test I am seeing error: ValueError: Eigenvalues did not converge I am unable to share ...
Deepali Chourasia's user avatar
0 votes
1 answer
146 views

I want to have a factory method that calls a cfunc using numpy arrays. I am trying to pass the numpy arrays by using a ctype pointer. Since my original code is rather complicated I have made a simple ...
Miguel Madeira's user avatar
3 votes
1 answer
122 views

I'm building a neural network from scratch using only Python and numpy, It's meant for classifying the MNIST data set, I got everything to work but the network isn't really learning, at epoch 0 it's ...
buzzbuzz20xx's user avatar
1 vote
1 answer
108 views

My goal is to save a huge 2d matrix as binary in kdb q, so that my python code can import it as numpy matrix. I played with numpy.fromfile and numpy.memmap but I don't think kdb is writing it into a ...
David Moss's user avatar
2 votes
1 answer
86 views

I am trying to create a random numpy array using np.random() but for some reason, instead of taking it as a function, google collab is taking it as a module, I checked the documentation, but I would ...
Aadvik's user avatar
  • 1,522
0 votes
1 answer
68 views

I am creating a simple NN from scratch that can classify MNIST digits, It only has 1 hidden layer:- Loading the data: import numpy as np import matplotlib.pyplot as plt from keras.datasets import ...
buzzbuzz20xx's user avatar
3 votes
2 answers
167 views

I have two lists of numpy arrays, and I want to check if the two lists have the same set of numpy arrays. If they have the same arrays in a different order, I still want it to return true. The numpy ...
Y F-N's user avatar
  • 43
1 vote
1 answer
77 views

I have the array import numpy as np a = np.array([[[11,12,13], [14,15,16]], [[21,22,23], [24,25,26]], [[31,32,33], [34,35,36]]]) # array([[[11, 12, 13], # [14, 15, ...
Bera's user avatar
  • 2,220
1 vote
1 answer
81 views

I'm trying to find the outer product of a large complex-valued vector (of size 91204) to later on find the it's partial trace using np.einsum. However I get the following error: numpy._core....
jnava1612's user avatar
4 votes
3 answers
163 views

I want to create a map (via the HTML "map" and "area" tags) with several unusually-shaped areas. The shapes are detailed enough that I don't want to write out all the coordinates ...
perihelions's user avatar
5 votes
1 answer
161 views

I'm in a performance critical field, where we store our results in pandas dataframes - issue is we are doing most of computations in numpy and then assigning to pd later - but this forces a copy on ...
Raven's user avatar
  • 831
0 votes
0 answers
55 views

I tried to run the code in the Tformer paper, but when I evaluated the model in the test section of the train function, it predicted that pred_np (labels) would all be 0. My expected pred_np would be ...
Long Edge's user avatar
1 vote
0 answers
48 views

Here is a translation of an C+MPI example in Python+Numpy+mpi4py. The goal of this example was to show that the message received is put in memory and that memory is in one dimension from mpi4py import ...
D. Lecas's user avatar
  • 111
5 votes
3 answers
101 views

I have created the following array, called X: array([[6.575], [6.421], [7.185], [6.998], [6.43 ], [6.012], [6.172], [5.631], [6.004], [6.377], [6.03 ]]) and I would like to create array([[6.575, 1], [...
Ashley Roughton's user avatar
1 vote
1 answer
131 views

This Python 3.13.5 script with numpy 2.2.6 and numba 0.61.2: import numpy as np, numba as nb @nb.njit(fastmath=True) def f(a, b): return np.histogram(a, 10, weights=b) a = np.random.randint(0, 256,...
Paul Jurczak's user avatar
  • 8,630
3 votes
4 answers
343 views

I have an array of the form a = np.array([1], dtype='uint8'). Now if I add 255 to a it will overflow and be np.array([0]). Is there a built-in way to "clip" to value to 255? NumPy has the ...
cards's user avatar
  • 5,280
3 votes
1 answer
129 views

This Python 3.12.7 script with numpy 2.2.4: import numpy as np a = np.random.randint(0, 256, (500, 500)).astype(np.uint8) counts, bins = np.histogram(a, range(0, 255, 25)) print(np.column_stack((...
Paul Jurczak's user avatar
  • 8,630
0 votes
0 answers
66 views

No matter which input I give it after training, it still spits the class distribution.. whereas if I just remove the hidden layer and use a single layer nn, it works much better. I know the proper ...
Turtleishly's user avatar
2 votes
3 answers
78 views

Consider the 3d numpy array arr: [[[ 0, 9, 0, 2], [ 6, 8, 0, 2]], [[ 0, 9, 1, 5], [ 4, 8, 1, 5]], [[ 1, 0, 1, 2], [ 6, 6, 1, 2]], [[ 0, 9, 1, 5], [ 5, 5, 1, 5]], [[ 0, 9, ...
user109387's user avatar
0 votes
2 answers
75 views

I have an array from which I want to select a number of rows, so that the rows selected don't vary if I repeat the sampling process. In my following code, this is not the case; each time I run the ...
Andrew's user avatar
  • 1,226
4 votes
1 answer
75 views

I'm working with a function in Python that constructs a 4×4 matrix based on inputs (x1, y1, x2, y2), and computes its eigenvalues and eigenvectors using np.linalg.eigh. Here is a simplified version of ...
Rinchen Sherpa's user avatar
2 votes
0 answers
77 views

I've written a tool in python that makes heavy use of numpy and pandas. Surprisingly, the tool is much slower on a brand new, high-end thinkpad as opposed to a ten year old Mac. To illustrate the ...
rhz's user avatar
  • 1,172
3 votes
2 answers
146 views

I have a $N\times N \times N$ array $a$ and would like to implement the formula $$ b_{ij} = \sum_k a_{i+k,j+k,k} $$ efficiently. Right now, I'm doing this via b = np.zeros((N, N)) for i in range(N): ...
Uroc327's user avatar
  • 1,471