Questions tagged [numpy-slicing]

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

Read more:

518 questions
1
vote
2 answers

Q: ValueError Keras expected conv2d_14_input to have shape (3, 12, 1) but got array with shape (3, 12, 6500)?

I am building a CNN for non image data in Keras 2.1.0 on Window 10. My input feature is a 3x12 matrix of non negative number and my output is a binary multi-label vector with length 6x1 And I was running into this error expected conv2d_14_input to…
1
vote
1 answer

transform n-dimensional numpy array to a 2D-array based on a variable in Python

I am trying to find the minimum value in an N-dimensional array spanned by (N-Parameters of varying values) and take out a 2-dimensional array spanned by 2 of the (N-Parameters) around the minimum value to make a contour plot. I can do this by hard…
JSM
  • 13
  • 2
1
vote
1 answer

How to indexing multi-dimensional arrays given by indices in a certain axis?

Let's say I have a 4d array A with shape (D0, D1, D2, D3). I have a 1d array B with shape (D0,), which includes the indices I need at axis 2. The trivial way to implement what I need: output_lis = [] for i in range(D0): output_lis.append(A[i, :,…
1
vote
1 answer

How to access to a specific tensor row?

how to extract specific rows in tensor? I'm a little confused. for example, let's say we want to have row 17 specified row import numpy as np np.random.seed(seed = 5) a = np.random.randint(10, size=(2,3,4,5)) a
Hemfri
  • 313
  • 1
  • 8
1
vote
0 answers

How to use fancy indexing and slice a numpy 3D array using a 2D index array's dimensions

So I am trying to refresh my knowledge. I tried finding the answer to this question here and I am not still not sure how to answer this. Basically if I have a 2D index array (call it a) of shape (x, z) and a 3D array (call it b) of shape (x, y, z),…
user278039
  • 139
  • 6
1
vote
2 answers

Query about picking values from numpy array

I have a numpy array of shape (206, 482, 3). I wanted to pick the 1st channel so I used name_of_array[:][:][0] but apparently that doesn't select the 1st channel. I think name_of_array[:,:,0] picks the 1st channel. I don't understand why. Why…
DLopezG
  • 115
  • 1
  • 5
1
vote
2 answers

Get mean along axis but with different subset of that axis in each cell

I need the mean along the time axis of array (1), using numpy. The catch: it's not going to be the mean of all values along this axis, but rather a subset that starts at an index that is given in array (2). The arrays I'm working with: (array1) 3…
1
vote
1 answer

Pythonic way of retrieving elements of 2D array by indices

Say I have this array of data data = np.asarray([[1, 2, 3, 4], ['a', 'b', 'c', 'd'], ['A', 'B', 'C', 'D'], ['x', 'y', 'z', 'zz']]) and these indices, each "pair" corresponding to one cell in the data matrix indices = np.asarray([[0, 0], [3, 0], [2,…
Maikefer
  • 570
  • 1
  • 8
  • 21
1
vote
1 answer

Slicing for creating Mini-batches

I intend to create mini-batches for my deep learning neural network program, from a training set consisting 'm' number of examples. I have tried: # First Shuffle (X, Y) permutation = list(np.random.permutation(m)) shuffled_X = X[:,…
1
vote
0 answers

Select a specific or all dimensions in numpy array with a variable

Basically I want to simply a function like this: arr = np.array([[0.2, 0.4], [-0.9, -0.8]]) def take_dimension(arr, dim=None): """dim is either None, 0 or 1""" # return array with specific dimension if dim is not None: …
NumesSanguis
  • 5,832
  • 6
  • 41
  • 76
1
vote
3 answers

Removal of outliers using numpy.argwhere

Hey guys this question might be more about logic than code, hopefully someone can light it up. So, I have a data list that contains some outliers, and I want to remove it by using the difference between each item on the list and identifying where…
Angel Lira
  • 293
  • 3
  • 12
1
vote
1 answer

Numpy ndarray assignment issue

I am not able to figure what out what is wrong with this piece of code. Could you please help me understand what is going wrong and how to fix it? import numpy as np T =…
xabhi
  • 798
  • 1
  • 13
  • 30
1
vote
0 answers

numpy delete isn't deleting full array of objs

I'm trying to split a dataset into train and test groups in Python using a method similar to what I'm used to in R (I realize there are other options). So I'm defining an array of row numbers that will make up my train set. I then want to grab the…
LMM3
  • 11
  • 1
1
vote
3 answers

Ways to filter specific value of array in numpy

I haven't use numpy to his full potential yet. I have this pretty huge 3d array (700000 x 32 x 32). All of the values are int between 1 and 4. I want to be able to filter the array so that the I get a same shape array, but only with 1 for values of…
1
vote
4 answers

Unexpected result from boolean mask slicing

I'm confused about the way numpy array slicing is working in the example below. I can't figure out how exactly the slicing is working and would appreciate an explanation. import numpy as np arr = np.array([ [1,2,3,4], [5,6,7,8], …
Myridium
  • 789
  • 10
  • 20