All Questions
1,827 questions
0
votes
1
answer
58
views
Cut-and-overlap reduction of N-dimensional array
Note: I have no idea what one might call this operation, so I've gone with "cut-and-overlap". Please let me know if there is an accepted terminology for something like this!
Intro
I need to ...
0
votes
1
answer
55
views
Writing to multidimensional arrays with variable dimension
I've initialized a list of arrays of different dimensions in Python and want to write to the entries of the arrays. If I want to write to the entry list[i, m1, m1, ..., m1, m2, m2, ..., m2] where m1 ...
-3
votes
1
answer
67
views
Why can't I stack 3D arrays with np.concatenate in numpy, while 1D and 2D arrays work?
I'm working with 3D numpy arrays and having trouble stacking two of them. Here’s what I’m trying to do:
import numpy as np
grid = np.arange(16).reshape((1, 4, 4))
grid2 = grid[:, :-1, ::-1].copy()
I ...
2
votes
4
answers
138
views
Why the result is different? Numpy Slicing and indexing
Basically I want to obtain a part of the variable "cubote". I tried two methods that should work in the same way, but it didn't.
My code:
import numpy as np
# Create a 3x3x3 cube
...
2
votes
3
answers
264
views
Python: Average Values in 2D-Array
I want to generate a twodimensional array in Python and I would like to iterate through each element and take an average. An element i should be averaged using the 8 surrounding array elements (...
1
vote
1
answer
87
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 ...
0
votes
0
answers
72
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 ...
4
votes
2
answers
121
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 ...
0
votes
0
answers
20
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 ...
1
vote
2
answers
742
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 = ...
2
votes
3
answers
86
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 =...
0
votes
1
answer
42
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 ...
-1
votes
1
answer
205
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 ...
0
votes
1
answer
41
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 ...
0
votes
1
answer
76
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 ...