Imagine that you have a tensor $T_{ijkl}$ (0<=i,j,k,l< N) that has the following property
T_{ijkl} is nonzero if i+j=k+l
which acts as a "selection rule".
You want to contract the tensor T with another tensor u to make a third tensor v as…
I am trying to avoid using list of lists and appending during my loop, so I've figured I can create a large np.zeros array, then use np.split to split it in batches, and populate the batches. The code looks like this:
N = inputData.size -…
I have a 3d numpy array A representing trigram language model. So A[i, i-1, i-2] is the probability $P(w_i|w_{i-1},w_{i-2})$, where $w$ are consecutive words. I want to extract all probabilities for a sequence of words. Now I am using the…
Let's say I have an array with size batch x max_len x output_size, where batch, max_len, and output_size all correspond to positive natural numbers. I have a list of indices which correspond to individual items in dimension 1 (i.e. max_len). How can…
I have a np.ndarray (call it arr) that looks something like this:
# python 3.7
import numpy as np
my_dtype = [("x", "float32"), ("y", "float32"),
("some_more", "int32"), ("and_more_stuff", "uint8")] #
part1 = np.zeros(5,…
I have a numpy array heatmap of shape (img_height, img_width) and another array bboxes of shape (K, 4), where K is a number of bounding boxes.
Each bounding box is defined
like so: [x_top_left, y_top_left, width, height].
Here's an example of such…
Given a matrix A, and a list of row indices, and a list of column indices, how to efficiently extract the squared submatrices with size k centered by the row and column indices?
For example:
A = array([[12, 6, 14, 8, 4, 1],
[18, 13, 8,…
I have an array of arbitrary shape, but let's say, (A, B, C), and I'd like to roll the last axis by a different amount for each element (i.e. for each (A, B)).
I'm trying to generalize @Divakar's beautiful solution here for 2D arrays, but I don't…
I've found similar questions posted here but none which apply to row-defined time series data. I'm anticipating the solution might be found via numpy or scipi. Because I have so much data, I'd prefer not to use pandas dataframes.
I have many runs…
Suppose I have a numpy array A which can be of any dimensions len(A.shape) can be 1,2,3,..etc. and a corresponding array, crop which len(crop) = len(A.shape) and I want to extract the interior values of A using crop. Here is an example for 2D…
I have a 3D data cube of values of size on the order of 10,000x512x512. I want to parse a window of vectors (say 6) along dim[0] repeatedly and generate the fourier transforms efficiently. I think I'm doing an array copy into the pyfftw package…
for some nd-array
a = np.zeros((2,5,4))
I want to slice the last dimension based on some boolean statement.
a[1,:, (True,True,True,True)].shape
however, returns (4,5) while I would expect a shape of (5,4) like from
a[1,:, :].shape
So, what's…
I have a numpy array from 0 to 999 and I would like to make a slice that runs from the last element in the list (999) to the one in the middle (500).
test[500:][::-1] works but if I have a two dimensional array and I only want to do so along the…
A short note: This question relates to another I asked previously, but since asking multiple questions within a single Q&A is concidered bad SO-style I splitted it up.
Setup
I have the following two implementations of a matrix-calculation:
The…