Skip to content

Tag: numpy

Slicing a 3D image to create a 2D image

I have several 3D images of shape (32,32,32) and I want to create 2D images from them. I want to do that by getting each slice in the z-axis and putting each of them in a square array in order, something like this: Because I want the 2D image to be square I need to fill the missing slices with

Problems adding strings to 2D array

So i’m simply trying to add certain strings to a NxN array(matrix) using a for loop. First I create an empty 2D array using np.empty to later fill up with my values: When I run this code I get a correct NxN array matrixK that is however only filled with ‘a’ at all indexes instead of ‘a…

Finding location of subarray in numpy array

I want to find the location of a subarray in an numpy array. For example, if the large array is of shape (10000, 10, 10, 10), namely 10000 arrays of shape (10,10,10) and I want to find the location of the subarray of shape (3,3,3) as follows: So I will know that at the location of n, i, j, k

How to find maximums’ indexes by row with Numpy?

I have np 2d array and want to get indexes of max by row. For example: Maximum by row is [3, 4, 2]. Indexes are [(0,0) (0,3) (1,1) (1,2) (2,4)] I tried smth like this buf = np.apply_along_axis(lambda x: zip(np.where(x == np.max(x))), axis=1, arr=B) or this buf = np.where(B == np.max(B,axis = 1)) But it doesnt…

dictionary inside column of a dataframe

I have a pandas dataframe that has a column like this : I want to make a condition on the whole dataframe based on the id value. I did many attempts but failed. it says key error, it cannot access ‘id’ which is inside the column ‘platform’. Any help is welcome, and thank you in advance…