Questions tagged [numpy-slicing]

questions related to numpy indexing routines, in particular, slicing, indexing and concatenation

Read more:

518 questions
1
vote
1 answer

Slice based on numpy.argmin results

Let us have a numpy array (float) with shape equal to (36, 2, 400, 400). Let us say the 400 by 400 represents an image. Then for each pixel I would like to find the two values (second dimension) which are when taking the norm over the second…
F.Wessels
  • 179
  • 11
1
vote
1 answer

Replace 2/3 of a multi-dimensional array given a condition

I have the following data >>> import numpy as np >>> original_classes=np.load("classes.npy") >>> original_features=np.load("features.npy") These NumPy arrays have the following shapes >>> original_classes.shape (12000,) >>>…
mad
  • 2,677
  • 8
  • 35
  • 78
1
vote
0 answers

How to parallelly slic several matrixes from a image in form of 2D numpy array

Given a image in form of 2D numpy array(etc, [H,W]), I want to slic several matrixes(etc, [N,N] N
MaTiezheng
  • 23
  • 3
1
vote
4 answers

Creating a discretized version of an array

I have a list that describes a profile, such as the next one: dat=[(0, 5),(1, 1),(3,1)] I need to create a discretized version of that profile give a step of time 'dt=0.2'. For instance, the firs column of 'dat' would be: dt = 0.2 time =…
nekovolta
  • 496
  • 2
  • 14
1
vote
2 answers

Index an array with the rows of another array

For example i have an array as a= [[[98, 92, 92, 81], [98, 26, 98, 36], [83, 39, 96, 73], [75, 36, 37, 68], [56, 87, 62, 73]], [[98, 43, 36, 96], [92, 88, 94, 71], [ 7, 24, 33, 18], …
1
vote
0 answers

Indexing a numpy ndarray in a custom class

I am relatively new to Python and I have written a class that contains a numpy.ndarray (containing ordinary Python int objects) for storing some data. I would like to implement __getitem__ and __setitem__ in a way that behaves intuitively for…
Harry
  • 884
  • 1
  • 8
  • 19
1
vote
2 answers

Combing and then maintaining indicies after numpy Logical Slicing

I am trying to conduct logical slicing on two lists and then concatenate them together while maintaining the original indicies. Here is what I currently have: x = np.array([0,12,2,246,13,42,245,235,26,33,235,236,23]) y =…
manninosi
  • 13
  • 4
1
vote
1 answer

How to scatter/send all possible column pairs to the child processes and find coherence between the columns using python mpi4py? Parallel computation

I've a big matrix/2D array for which every possible column-pair I need to find the coherence by parallel computation in python (e.g. mpi4py). Coherence [a function] are computed at various child processes and the child process should send the…
pluto
  • 88
  • 8
1
vote
1 answer

Add a column to an array with values from a position in another array if rows match

I have two arrays, one looks like this: [[1 2 1 0 2 0 1] [1 2 1 0 2 0 1] [1 2 1 0 2 0 1] [1 2 1 0 2 0 1] [0 1 2 1 0 0 2] [0 1 2 1 0 0 2] [0 0 1 0 1 0 3] [0 0 0 1 1 0 4] [0 0 0 0 1 0 5] [0 0 0 0 0 1 6]] The other looks like this: [[1 2 1 0 2 0] [1 1…
Gus
  • 193
  • 9
1
vote
1 answer

Slicing a multiindex pandas dataframe using xs

I have a df df_test = pd.DataFrame.from_dict({('group', ''): {0: 'A', 1: 'A', 2: 'A', 3: 'A', 4: 'A', 5: 'A', 6: 'A', 7: 'A', 8: 'A', 9: 'B', 10: 'B', 11: 'B', 12: 'B', 13: 'B', 14: 'B', 15: 'B', 16: 'B', 17: 'B', …
Jonas Palačionis
  • 4,591
  • 4
  • 22
  • 55
1
vote
1 answer

precisely slice a 3d array in python

I want to slice a 3D array [-500:500] to subarrays in sequence 100 subarrays of length 2 then one of length 50 then 100 of length 2 then one of length 50, and I wish every subarray is spaced by length one from the following.
1
vote
1 answer

Comparing 2 CSV files with different length and find out additional data

I have two CSV files, both have different numbers of rows and Columns, in File 1, I have the below structure, PRODUCT NAME PRODUCT TYPE PRODUCT SERIAL Galaxy S6 Android Phone IAJ83934830485 Surface Pro Windows Tablet IM94545435493 iPhone…
re-learn
  • 13
  • 3
1
vote
1 answer

Slicing Numpy ndarray

I have used numpy to split a string at each ,. The output shows the split words. When I want to retrive first element, I get the following error: IndexError: too many indices for array: array is 0-dimensional, but 1 were indexed. Code item =…
Lima
  • 11
  • 2
1
vote
0 answers

Changing values of sliced arrays in numpy

I made a simple array X like this one import numpy as np X=np.arange(1,10).reshape(3,3) Then I made these two arrays that give me the exact same output by slicing X A=X[:2,:2] B=X[np.array([0,1])[:,np.newaxis],[0,1]] If I change a value in A…
Hajin Lee
  • 49
  • 1
  • 3
1
vote
1 answer

Complex indexing of a multidimensional array with indices of lower dimensional arrays in Python

Problem: I have a numpy array of 4 dimensions: x = np.arange(1000).reshape(5, 10, 10, 2 ) If we print it: I want to find the indices of the 6 largest values of the array in the 2nd axis but only for the 0th element in the last axis (red circles…
Puco4
  • 491
  • 5
  • 16