Skip to main content
Filter by
Sorted by
Tagged with
2 votes
1 answer
106 views

If I know the shape of a numpy array like (1000, 50), and I have an arbitrary selection expressed as an IndexExpression, let's say np.s_[:200, :], how can I evaluate the shape of the sliced array (in ...
Kyle's user avatar
  • 364
1 vote
1 answer
82 views

Is there a simple syntax for creating references to an arbitrary number of neighbouring array elements in numpy? The syntax is relatively straightforward when the number of neighbours is hard-coded. A ...
DavidJ's user avatar
  • 440
1 vote
1 answer
63 views

I have a 3D array (121, 512, 1024) made up of frames of 512x1024 images. The bottom several rows of the images have Nans which mess up my processing. I want to remove these and end up with something ...
Spectroscopist1812's user avatar
0 votes
0 answers
54 views

I am writing a function to bin points based on their angle in a radial coordinate system. I would like to have the option to perform some nonlinear downsampling of the points in each bin (computing ...
Gtingstad's user avatar
2 votes
1 answer
119 views

Given a numpy array of dimension n with each direction having length m, I would like to iterate through all 1-dimensional arrays of length m. For example, consider: import numpy as np x = np.identity(...
Matt's user avatar
  • 155
1 vote
3 answers
81 views

The following snippet: import numpy as np x = np.arange(25).reshape(5, 5) print(x.base) y = x[:2, [0, 2]] print(y.base) outputs [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...
Antonios Sarikas's user avatar
0 votes
0 answers
26 views

I am using NumPy version 2.1.3 and Python 3.12.2. Say I define ones_arr = np.ones((1, 2, 3)) Now I slice ones_arr[0, :, [0, 1, 2]] The result has shape (3, 2), but I would expect it to have shape (2,...
lmbell's user avatar
  • 43
1 vote
2 answers
57 views

I have integer arrays of the type: import numpy as np seed_idx = np.asarray([[0, 1], [1, 2], [2, 3], [3, 4]], dtype=np.int_) ...
Ben's user avatar
  • 539
0 votes
0 answers
62 views

Say I have a 4 dimensional C++ std::vector, x. In the numpy's notation, I can easily get access to a sub-vector y=x[:, :, :, 2] using slicing. In cpp, is there a fast way to do this? A naive way is of ...
Tony Shi's user avatar
0 votes
2 answers
194 views

The Question: Here is a simple function that works with numpy but not numba: # @numba.jit(nopython=True, fastmath=False, parallel=False) def testgetvalue(tgvarray, tgvindex): tgvalue = ...
Nathan Gabriel's user avatar
2 votes
2 answers
64 views

I have a three dimensional numpy array. What is the fastest way to get a 3D array that has the largest item of each of final axis of the array without writing a loop.(I will later use CuPy with the ...
Mikael's user avatar
  • 33
1 vote
2 answers
173 views

Starting from this situation: I would like to create a boolean mask where all external points are considered as True while all internal point are False. Something like this : The objective would be ...
Certes's user avatar
  • 159
3 votes
2 answers
95 views

There are multiple questions on StackOverflow, asking how the comma syntax works, but most of them refer to m[:,n] which refers to the nth column. Similarly, m[n,:] refers to the nth row. I find this ...
Shirsak's user avatar
  • 57
0 votes
0 answers
49 views

(Aside: my question is equally applicable to numpy structured arrays and non-structured arrays.) Suppose I have a numpy structured array with the dtype: EXAMPLE_DTYPE = np.dtype([("alpha", ...
bzm3r's user avatar
  • 4,664
5 votes
1 answer
347 views

The following code import numpy as np x = np.arange(32).reshape(2,2,2,2,2) extra = [1 for _ in range(3)] print(x[*extra, 0, 0]) prints 28 as expected in Python 3.12 but results in the syntax error ...
D. Song's user avatar
  • 153
0 votes
0 answers
42 views

I have a numpy array with shape (M, N, N) - it's effectively a bunch (M) of (N,N) covariance matrices. I want to be able to extract submatrices out of this with shape (M, P, P). But I'm trying to ...
Tom Johnson's user avatar
  • 2,224
0 votes
1 answer
45 views

The following is a real-world problem in numPy reduced to the essentials, just with smaller dimensions. Let's say I want to create an n-dimensional array all with dimensions (10, 10, 100): all = np....
MichaelW's user avatar
  • 1,502
0 votes
1 answer
174 views

I appreciate it if you can provide me with one-line code. I used np.flip but I want a different approach to make it generalized. This was my code: np.flip(image, 1) I also used np.fliplr(image). Note: ...
Amirparsa Rouhi's user avatar
0 votes
4 answers
377 views

I want to split a torch array by a list of indices. For example say my input array is torch.arange(20) tensor([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) ...
piccolo's user avatar
  • 2,227
0 votes
1 answer
463 views

I installed NUMPY by using pip install NUMPY and it installed and then I'm still not able to use np. method . the NUMPY version is 1.26.3. the error in "np is not defined". can somebody ...
Mehran Kaj's user avatar
0 votes
1 answer
133 views

I am looking for the numpythonic way to accomplish the following: A = np.arange(1000) x = np.array([0, 10, 20, 30], dtype=int) dx = np.array([3, 4, 5, 6], dtype=int) for x_, dx_ in zip(x, dx): ...
Sterling Butters's user avatar
1 vote
1 answer
55 views

A = np.array([ [-1, 3], [3, 2] ], dtype=np.dtype(float)) b = np.array([7, 1], dtype=np.dtype(float)) print(f"Shape of A: {A.shape}") ...
user1965449's user avatar
  • 2,931
1 vote
1 answer
145 views

I am trying to use the finite difference method with NumPy arrays, but the slicing is incredibly slow. It's not viable to use lists as I am applying math operations. Using matlab, equivalent code is ...
THATS MY QUANT MY QUANTITATIVE's user avatar
1 vote
1 answer
113 views

I need to calculate a moving average over a 3D array with a step size set by me. What I am doing right now is img = np.ones(10,10,50) img_new = bottleneck.move.move_mean(img, window=5, axis=2) ...
emely_pi's user avatar
  • 701
-1 votes
1 answer
146 views

I have a numpy array of n x m values, which may look something like this: [[ 1, 2, 1, 3, 5], [ 0, 4, 2, 4, 1], [ 1, 1, 1, 0, 2]] I want to calculate the difference and mean from every grid point to ...
Simon M's user avatar

1
2 3 4 5
12