I have a numpy array A of shape (550,10). I have batch size of 100 i.e how much data rows I want from A. In each iteration I want to extract 100 rows from A. But when I reach last 50 rows, I want last 50 and first 50 rows from A.
I have a function…
Given a 2D array and two pairs of indices, defining the upper left and lower right corner of a sub-matrix respectively:
a = np.arange(25).reshape(5,5)
# array([[ 0, 1, 2, 3, 4],
# [ 5, 6, 7, 8, 9],
# [10, 11, 12, 13, 14],
# …
I have the following 3D array of shape
In [159]: arr = np.arange(60).reshape(3, 4, 5)
And I'm trying to do advanced indexing to extract a sub-array like:
# behaves as expected
In [160]: arr[[1, 2], :, 1].shape
Out[160]: (2, 4)
In the following…
I am writing a function that takes three inputs: a numpy array, a number, and another number.
I want to take a slice of the array, and replace the first value with another value.
I do not want to modify the original array passed into the function as…
I have a large 2D array (A) and a smaller 2D array of the same number of columns but fewer number of rows (B). I want to add the rows of my smaller array to rows of my larger array, but there are rows in between that I don't want to affect. I have…
Let's assume I have a huge (actually, it would have around a ~1_000_000 values) numpy array of floats.
data = np.arange(100).astype(np.float64)
In parallel I created two numpy arrays of integers (that would be indices later on)
a =…
I have a piece of code that has to generate a gaussian distribution over a few pixels of an image based on a set of coordinates and a confidence.
import numpy as np
def gen_single_joint_heatmap(x, y, conf, img_size, sigma=0.6, eps=1e-6):
heatmap =…
I currently have an input grid and function which i'd like to pass onto every element of the grid (dependent on the number of dimensions of the original grid). Issue is, I currently have several different implementations of passing the function…
Consider a Numpy array C of shape (s_1,...,s_k) and another array A of shape (s_j,...,s_k) where j > 1. Is there a function in Python to return the list [p_1,...,p_l] of positions of the form p_r == [x_1,...,x_{j-1}] such that C[x_1,...,x_{j-1}] ==…
I have a numpy array x with shape [4, 5, 3]
I have a 2D array of indices i with shape [4, 3], referring to indices along dimension 1 (of length 5) in x
I'd like to extract a sub-array y from x, with shape [4, 3], such that y[j, k] == x[j, i[j, k],…
Suppose that I have an image of three channels, and its corresponding numpy array is of the shape (H,W,3).
Now I create a function which does something to a 2D numpy array.
How can I apply the funtion to each channel of the image without using a…
Let A be a simple python class that has one member self._mat which is a numpy array.
The constructor of A gets an integer n and creates an inner n by n zeros numpy array and saves it as the private member self._mat.
How can I implement __getitem__…
So my issue is that I'm trying to paste a small image into a larger image with the typical numpy syntax :
large_im = np.linspace(0,1,20)[:,None]*np.ones([1,20])
small_im = np.linspace(1,0,10)[None,:]*np.ones([10,1])
a0,b0 =…
I have 10 seconds of data from 7 devices each with 2 channels in a 1D array, sampled at 51.2KHz.
I split the array into to 10
time_split = np.array_split(data, 10)
I then split each element of time_split into the samples for each…