All Questions
Tagged with multidimensional-array python
3,716 questions
0
votes
1
answer
89
views
how to create uniform nested lists and convert them in to multi dimensional arrays?
i would like to create a nested list of arbitrary depth (containing numerical values specifically) with uniform arbitrary lengths at each level and then compress it to a NumPy array of minimum ...
0
votes
0
answers
37
views
How to convolve a 3D array with Lorentzian kernel along axis=2?
I have an array img_data of shape (x, x, n_channels) and I want to convolve / smooth along the axis=2.
Specifically, I would like the output shape to be (x,x,n_channels//3), after convolving the ...
0
votes
1
answer
69
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 ...
1
vote
0
answers
90
views
How to interpolate a multidimensional xarray DataArray?
I am using the xarray library and I have some doubts/questions.
I have this dataset::
ds
<xarray.Dataset> Size: 2GB
Dimensions: (Latitude: 364, Longitude: 246, Lon_u: 247, Lat_v: 364,
...
0
votes
0
answers
50
views
Extensive merging of nested list with capacity restriction
I have a nested list on which I want to perform merging under certain restrictions.
This is my nested list:
[[[0.0, 2.0], [6.0, 20.0]],
[[0.0, 5.0], [6.0, 12.0]],
[[2.0, 5.0], [20.0, 12.0]...
3
votes
2
answers
92
views
Adding 2D numpy arrays with differing axes arrays: how to properly replace the deprecated interp2d with RectBivariateSpline?
I need to add two 2D numpy arrays of possibly different shapes and different corresponding axes arrays.
What I mean is this: Lets define two different sets of x- and y-axes, and calculate the z-values ...
2
votes
3
answers
316
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 (...
2
votes
3
answers
79
views
Appending multiple dictionaries to specific key of a nested dictionary
I want to append different dictionaries having the key as the meal_name and having total_calories and total_protein as a tuple being the value of the dictionary without overwriting the original ...
0
votes
2
answers
109
views
Why are all rows of my matrix the same as the last row?
Can someone please help me find fault in my code? If I create a blank 2D matrix with static initial value, it returns the correct transposed matrix. Whereas if I create a blank matrix using a for loop,...
0
votes
0
answers
76
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 ...
2
votes
0
answers
56
views
Video codec for 3D volumetric video datasets
I have 3D volumetric MRI scans representing a time series. So the sequence of these 3D volumes presents a video composed of voxels rather than the conventional 2D pixels from traditional 2D videos. ...
2
votes
0
answers
27
views
3D scatterplot, matrix operations and calculation of the inverse
I have a scatter-plot with the code shown below.
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
x = np.random.rand(100)
y = np.random.rand(100)
z = np....
0
votes
1
answer
24
views
resizing two arrays to be used in a DataFrame
I'm trying to create a pandas DataFrame from a dictionary. We know that to do so, all the dictionary elements must be of the same dimension. The dictionary is composed of two ndarrays; one with the ...
0
votes
0
answers
23
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 ...
0
votes
4
answers
125
views
How to calculate total sum of all the elements present in the list. The elements in the list can be integers or nested lists
def calculate_total_sum(arr):
# Your code here
sum=0
for i in range(len(arr)):
for j in range(len(arr[i])):
sum=sum+arr[i][j]
print(sum)
list1=[int(x) for x in ...
0
votes
1
answer
64
views
Heatmap plot with weirdly shaped data
so I am trying to create a heatmap plot for x, y data that are shaped as following:
xs, ys, corrs = [], [], []
for x in np.linspace(0.1,5,25):
xs.append(x)
for y in np.linspace(0.01,x,25):
...
-1
votes
1
answer
240
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
84
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 ...
0
votes
1
answer
77
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 ...
3
votes
2
answers
190
views
Numpy array methods are faster than numpy functions?
I have to work with the learning history of a Keras model. This is a basic task, but I've measured the performance of the Python built-in min() function, the numpy.min() function, and the numpy ...
0
votes
1
answer
158
views
How to extract 3D arrays of points (blobs) from a binary 3D array?
I have a numpy array of shape (260,311, 260) of points. It represents 8 electrodes (value 1) in an empty space (surrounded by zeroes). How can I detect these blobs and individualize them one by one? (...
0
votes
1
answer
69
views
Python - convert from JSON to CSV
I am trying to achieve a conversion of some JSON data to CSV for a later analysis.
Issue is due to the n-nested levels, I think, and mainly for the last stage of the conversion process.
So far, I have ...
1
vote
1
answer
76
views
Is there a way to efficiently construct a 3d array from symmetric submatrices of a 2d array according to an array of different index sets?
I have a two-dimensional array A, and another two-dimensional array I where each row corresponds to a set of indices with which I want to extract symmetric two-dimensional subarrays from A. I want to ...
0
votes
1
answer
79
views
How to return a match and no match in two 2d list
I have two 2d list with over 200 rows. I would like to find match in df1 and df2 in each sub-list and return non-matching and matching values only if the values match in df1,df2.
Here a short example
...
1
vote
1
answer
89
views
Return more than 2 duplicates in each sublist (2d list)
I have a large 2d list that has duplicates in some sublists. I would like to return 2 or more duplicates and return the duplicates first if impossible. For instance,
Df =[[2,3,5,20],[5,10,20,10],[4,...