Questions tagged [numpy-slicing]

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

Read more:

518 questions
1
vote
0 answers

how to slice a texture2d in unity programmatically like i want to divide my texture in to two parts

my input is texture2d which is 4 channel one so i have to divide the 2 parts of it kind of slicing how can?? i have tried it creating other mat and tex and copied till half of the texture Mat slice = imageMat.submat(0,0,image.height, 330); byte[]…
Vamshi Krishna
  • 61
  • 1
  • 1
  • 2
1
vote
1 answer

I am trying slicing but I have the following error message: slice indices must be integers or None or have an __index__ method

I am trying slicing but I have the following error message: slice indices must be integers or None or have an __index__ method descriptors = numpy.fft.fftshift(descriptors) center_index = len(descriptors) / 2 descriptors = descriptors[center_index -…
UM_Hasan
  • 3
  • 3
1
vote
2 answers

NumPy Slicing with Multiple Tuples

Consider the following: import numpy as np arr = np.arange(3 * 4 * 5).reshape((3, 4, 5)) If I slice arr using slices, I get, e.g.: arr[:, 0:2, :].shape # (3, 2, 5) If now I slice arr using a mixture of slice() and tuple(), I get: arr[:, (0, 1),…
norok2
  • 25,683
  • 4
  • 73
  • 99
1
vote
2 answers

Slicing a 2D array using indices 1D array

I have a 2D array of (10,24) and a 1D array of (10,) shape. I want to slice a 2D array using 1D array such that my resultant array will be (10,24) but the values are sliced from indices in 1D array onwards. import numpy as np x1 =…
Abhishek Jain
  • 568
  • 2
  • 4
  • 15
1
vote
1 answer

Numpy slicing multidimensional error produces unexpected result

I have a multidimensional array of this shape: (2, 200, 2, 3, 3, 114) I would like to extract a specific set of values from it using this command: pab[0][:][0][0][0][i] So basically I need each value iterated over the second dimension for fixes…
JRsz
  • 2,891
  • 4
  • 28
  • 44
1
vote
3 answers

Logic operation: Select two values from a column in a dataframe

I have a data frame as follows, df2 = pd.DataFrame({'a' : ['one', 'one', 'two', 'three', 'two', 'one', 'six'], 'b' : ['x', 'y', 'y', 'x', 'y', 'x', 'x'], 'c' : np.random.randn(7)}) I want to select data from…
1
vote
1 answer

How to broadcast different slices for each row?

I'm operating on a numpy 2-d array and trying to find some way to access different slices per row. Preferably exploiting numpy broadcasting in such a way that I pass an array of slices like follows: A =…
Matthew K
  • 189
  • 2
  • 12
1
vote
0 answers

How to create meshgrid with non-integer stepsize of list elements?

I have 2 lists of x and y coordinate that are independently generated, with a/h amount of points between 0 and a. x = np.linspace(0, a, a/h) y = np.linspace(0, d, d/h) when a/h is such that 0 increases to a in steps of integers i.e. [0,1,2,..,a].…
user3613025
  • 373
  • 3
  • 10
1
vote
2 answers

Custom NumPy Slice

I have a bunch of numpy arrays that can differ in shape: [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]] I need to select and store the indices into a variable so that I can change the array into: [[1, 1, 1, 1, 1], [1, 1,…
slaw
  • 6,591
  • 16
  • 56
  • 109
1
vote
2 answers

Shuffling list of locations in a 2D numpy array and then use it to select (or slice) in a 3D numpy array

I'm working with a 3D array of which the index array is a 200x200 binary array (for classification). This array contains either 0 or 1 and I need to use this array select a random 1000 locations of 0 and a random 1000 locations of 1 in the 3D array.…
1
vote
3 answers

How to select row or column from a matrix?

Here I have a matrix a=np.array([[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]]) I want to select all rows, but the column I want to select is from the first to the third one. It should be [[1,2,3],[6,7,8],[11,12,13]] However, I have ever tried…
陳俊良
  • 319
  • 1
  • 6
  • 13
1
vote
1 answer

Why is slicing using "colon and comma" different than using a collection of indexes

Why is slicing using "colon and comma" different than using a collection of indexes? Here is an example of what I expected to yield the same result but but it does not: import numpy as np a =…
1
vote
0 answers

numpy rearanging when mixing integer and list indices

I have a 3d array in numpy that I would like to index on two of these axes. For one of the axes I am using a simple integer index, whereas on the other axis I use a list indexing. If I apply the indexes separately, the result is different from when…
Milla Well
  • 3,193
  • 3
  • 35
  • 50
1
vote
0 answers

Slice numpy array of dimension N with array of dimension N-1

I'm looking for the most idiomatic and performant way to slice an array of dimension N with an array of dimension N-1 that represents the index of the last dimension to slice. The output would have dimension N-1. As an example: import numpy as…
thomas
  • 51
  • 1
  • 5
1
vote
1 answer

Triangular Numpy Slicing

I wanna slice a 2D numpy array between 3 coordinates, for example, given this numpy, [[0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0]] and coordinates (1,1) (3,1) (3,5), I want this: [[0 0 0 0 0 0 0 0] [0 1 0 0 0 0 0 0] …
Ali Abbasi
  • 894
  • 9
  • 22