numpy-slicing

how to use fromiter and ndnumerate together

how to use fromiter and ndnumerate together Question: I’m currently trying to manually implement a function to represent the KNN graph of a set of points as an incidence matrix, and my idea was to take the rows of an affinity matrix(n x n matrix representing the distance between the n points), enumerate and sort …

Total answers: 2

How can I use a 3d array of indices for a 2d array slicing in Numpy

How can I use a 3d array of indices for a 2d array slicing in Numpy Question: I have 2 arrays as input. On array as output. Array a holds the data and is of shape (N,M), while array b holds the indices and is of shape (N,X,2). The resulting array should be of shape …

Total answers: 1

How to retrieve elements from an array without slicing?

How to retrieve elements from an array without slicing? Question: Say I have an array, A1. B1 is another array storing the last two rows of A1. I need to retrieve the first two rows of A1 without slicing as another array (C1). Logically, I’m thinking something like A1 (the whole array) – B1 (the …

Total answers: 2

using integer as index for multidimensional numpy array

using integer as index for multidimensional numpy array Question: I have boolean array of shape (n_samples, n_items) which represents a set: my_set[i, j] tells if sample i contains item j. To populate it, the array is initialized as zeros, and receive another array of integers, with shape (n_samples, 3), telling for each example, three elements …

Total answers: 1

how to color highlight pandas data frame on selected rows

how to highlight pandas data frame on selected rows Question: I have the data like this: df: A-A A-B A-C A-D A-E Tg 0.37 10.24 5.02 0.63 20.30 USL 0.39 10.26 5.04 0.65 20.32 LSL 0.35 10.22 5.00 0.63 20.28 1 0.35 10.23 5.05 0.65 20.45 2 0.36 10.19 5.07 0.67 20.25 3 0.34 10.25 …

Total answers: 1

How to get 'n' elements before Nth index of a list in Python?

How to get 'n' elements before Nth index of a list in Python? Question: I want to iterate over a large list wherein I need to do some computations using n elements before the Nth index of the large list. I’ve solved it using the following code snippet. mylist = [1,2,3,4,5,6,7,8,9,10,11,12,13,14] for i in range(len(mylist)): …

Total answers: 4

Maxpooling 2×2 array only using numpy

Maxpooling 2×2 array only using numpy Question: I want help in maxpooling using numpy. I am learning Python for data science, here I have to do maxpooling and average pooling for 2×2 matrix, the input can be 8×8 or more but I have to do maxpool for every 2×2 matrix. I have created an matrix …

Total answers: 3

Selecting specific rows and columns from NumPy array

Selecting specific rows and columns from NumPy array Question: I’ve been going crazy trying to figure out what stupid thing I’m doing wrong here. I’m using NumPy, and I have specific row indices and specific column indices that I want to select from. Here’s the gist of my problem: import numpy as np a = …

Total answers: 4