Skip to content

Tag: arrays

Numpy: Indexing 3D matrix using 1D array

I’m trying to index this array of shape (3,2,2) with an array of shape (3) containing the y-index of the value I want to get. I tried to make it work with for in statement, but is there an elegant way to do it with numpy? Answer So you want arr[0,0,:], arr[1,1,:], arr[2,1,:]? How about

Convert rec.array to dataframe

I’ve been trying to convert a numpy rec.array into a dataframe. The current array looks like: The result should be a five-column dataframe like the following: Weights v_1 v_2 v_3 v_4 0.2 1.76405235 0.40015721 0.97873798 2.2408932 0.2 1.86755799 -0.97727788 0.95008842 -0.15135721 …. …. &#8230…

Numpy Delete not deleting rows

I’ve been trying to write some code to delete rows from my 2d array according to the following criteria: every lone entry, so that no patient only has one entry (the mriindex ticks up by 1 for every entry of the same patient in the array) every entry above the 4th one. Should either of those criteria be…

All possible combinations of arrays in python

I have a problem finding all combinations of a 2D array. Let’s suggest I have an array as follwoing: Now I need to get all possible combninations such as I’ve managed to get it with numpy and meshgrids with single arrays: But with a 2D array I cant’t get it to work. This doesn’t give m…

How do I print name of array in Python?

I have few arrays, in my code. I wanna be able to change, which I am using in one place, and to be able to print name of it only changing one line (definition). Example: Now I want to have in print being to able call XYZ array not my_array. So I don’t have to change it twice, but It

Setting integers inside array to a fixed length

I´m trying to generate an array with integers of a fixed length of 6, so that e.g. 1234 is displayed as 001234 and 12345 as 012345. I can get it to work for an integer using: I tried the same method for an array, but it doesn`t seem to work, so how can I convert this method to array entries?