Skip to main content
Stack Overflow
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
Advice
3 votes
2 replies
58 views

I'm trying to re-shape a rather large array of encoded data efficiently. The original array (orig_array) is encoded using thermometer encoding (enc_array) import numpy as np from numpy.lib....
2 votes
1 answer
110 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
0 votes
0 answers
62 views

Heyo, I am new to JAX and I am trying to make my code jit-compatible so it runs faster on big data arrays. Here are the functions I am trying to write using JAX: @jax.jit def logL(p, clustering): ...
1 vote
1 answer
92 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 ...
1 vote
3 answers
90 views

I want to finding a general formula or algorithm to determine all possible values of `step` that satisfy the three conditions (boundary, equal spacing, and symmetry) when slicing an array with the ...
1 vote
1 answer
69 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 ...
2 votes
1 answer
61 views

I have a large (90k x 90k) numpy ndarray and I need to zero out a block of it. I have a list of about 30k indices that indicate which rows and columns need to be zero. The indices aren't necessarily ...
3 votes
1 answer
147 views

I am looking for a way to vectorize the following code, # Let cube have shape (N, M, M) sub_arrays = np.empty(len(cube), 3, 3) row_start = ... # Shape (N,) and are integers in range [0, M-2] row_end ...
2 votes
1 answer
124 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
0 votes
2 answers
116 views

could you please help demystify the following numpy indexing/slicing behaviours? Thanks! arr = np.arange(60).reshape(3,4,5) print(arr[2, :, 4]) #1 print(arr[[2], :, 4]) #2 print(arr[2, :, [4]])...
1 vote
3 answers
91 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 ...
2 votes
1 answer
180 views

I'm writing a code and I have a function that calculates the values that are not fulfilling a condition with the values that are fulfilling the condition, but I'm having a lot of trouble with managing ...
0 votes
0 answers
29 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,...
0 votes
1 answer
41 views

If I have a vector vec, I can index it with a matrix as follows: import numpy as np vec = np.asarray([1,2,3,4]) # Shape (4,) mat = np.asarray([[0,2], [3,1]]) # Shape (2,2) result =...
1 vote
2 answers
60 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_) ...

15 30 50 per page
1
2 3 4 5
...
38

AltStyle によって変換されたページ (->オリジナル) /