Skip to main content

All Questions

1 vote
1 answer
71 views

How do I effectively compute pairwise quantities in numpy?

I want to compute pairwise quantities, e.g. distances between two points. A simple example would be import numpy as np N = 9 x = np.linspace(0,1,N) y = np.abs(x - x[:,None]) # pairwise 1d eucdlidian ...
knods's user avatar
  • 23
0 votes
0 answers
54 views

Interpolate y-value given x-value and data value in a 2D array

I am working with a 2D dataset with the x and y dimensions representing two separate variables, and the combined 2D grid representing a third variable. Here's a visual example of the dataset and the x ...
bashful_creature's user avatar
4 votes
2 answers
112 views

Optimal multiplication of two 3D arrays having a variable dimension

I would like to multiply tensors R = {R_1, R_2, ..., R_M} and X = {X_1, X_2, ..., X_M} where R_i and X_i are 3×3 and 3×N_i matrices, respectively. How can I make maximum use of NumPy functionalities ...
TobiR's user avatar
  • 143
0 votes
1 answer
91 views

How to understand transpose operation on a 3D or Higher Dimensional Array

Consider a 3D array array_3d with shape (3, 2, 2): array_3d = np.array([ [[ 0, 1], [ 2, 3]], [[ 4, 5], [ 6, 7]], [[ 8, 9], [10, 11]] ]) array_3d.shape = (3, 2, 2) ...
Abdulla Saeed's user avatar
0 votes
0 answers
19 views

error: all the input arrays must have same number of dimensions, but the array at index 0 has 1 dimension(s) and the array at index 1 has 2 dimensions [duplicate]

Getting the below error while executing the code for the ravdess dataset /usr/local/lib/python3.10/dist-packages/librosa/core/spectrum.py:266: UserWarning: n_fft=2048 is too large for input signal of ...
Yash489's user avatar
1 vote
2 answers
124 views

ValueError: could not broadcast input array from shape A into shape B

I used Python with Numpy to create an array filled with numbers from a tuple, and set it up to be a 4x4 matrix. numbers = (-8, -3, -5, 0, 4, 5, 6, 10, 7,8, 9, 100, 10, 11, 12, 1000) numbers_array = ...
xgzvsx's user avatar
  • 11
2 votes
3 answers
53 views

Numpy slicing on a zero-padded 2D array

Given a 2D Numpy array, I'd like to be able to pad it on the left, right, top, bottom side, like the following pseudo-code. Is there anything like this already built into Numpy? import numpy as np a =...
Basj's user avatar
  • 44.9k
0 votes
1 answer
45 views

NumPy ndarray non contiguous memory layout

I need some help in understanding the equations involved in finding the index of an element in an ndarray. I have been reading the Book "Guide to NumPy" by Travis A Oliphant. Link to the ...
user3851878's user avatar
0 votes
1 answer
30 views

3d numpy array output, meant to emulate an image, can't convert to Image

I am creating an autostereogram with the function make_autostereogram. It is being output as a 3d NumPy array (rows, colums, RGB). It is then input into the Pillow function fromarray(). It has array ...
T. J. Foster's user avatar
-1 votes
1 answer
59 views

Numpy Broadcasting - Need complete understanding

I am trying to understand Numpy Broadcasting. So I want to understand why is the below code working? a = np.arange(4).reshape(2,2) b = np.arange(6).reshape(3,2) a = a[:, np.newaxis] a + b I mean if ...
user3851878's user avatar
0 votes
1 answer
39 views

Why are my numpy array elements being cast to lists?

import numpy as np ar1 = np.array([[[1,2,3],[4,5,6]],[[1,2,3],[4,5,6]]]) ar2 = np.array([[[1,2,3],[4,5,6]],[[1,2,3,4],[4,5,6,7]]]) print(ar1) print(ar2) When I run this the second array prints out ...
CMR's user avatar
  • 13
0 votes
1 answer
67 views

How can I speed up the processing of my nested for loops for a giant 3D numpy array?

I created a very large 3D numpy array called tr_mat. The shape of tr_mat is: tr_mat.shape (1024, 536, 21073) Info on the 3D numpy array: First and before going into the actual code, I would like to ...
Philipp's user avatar
  • 415
1 vote
3 answers
97 views

Implementing 2D sliding window over np.array without overlaps (tiling, mean pooling)

I'm trying to implement 2D sliding window of cubic shape (k,k), to so I can iterate over a frame (n,m,3) and calculate the mean over the pixel values in each window. I want each iteration, that the ...
gaviezri's user avatar
0 votes
1 answer
66 views

Fix this numpy-function so it accepts multidimensional inputs

I am trying to compute the following function: geo-decay-function: in numpy, has to be vectorized. The catch in this case is that it should work for multidimensional inputs. E.g., x having dimensions ...
rutkov's user avatar
  • 1
1 vote
1 answer
111 views

Implementing 1D interpolation on a 3D Array in Numpy or Xarray

I have been attempting to find a way to utilize np.interp() to interpolate the innermost dimension of a 3D array: Say I have a 3D array with shape: (lat,lon,depth) = (3,3,4) as a toy example: ...
arctic_climate_science's user avatar

15 30 50 per page
1
2 3 4 5
141