Skip to content

Tag: numpy

Iterate over inner axes of an array

I want to iterate over some inner dimensions of an array without knowing in advance how many dimensions to iterate over. Furthermore I only know that the last two dimensions should not be iterated over. For example assume the array has dimension 5 and shape (i,j,k,l,m) and I want to iterate over the second an…

How to prevent np.where from turning 0 into ‘0’?

I want to create an array with np.where that has strings and 0s in it. So usually its dtype would be ‘object’. Minimal example: As a result I get I would like those ‘0’s to be 0s. Since np.where has no argument for dtype, I don’t know how to do this except by replacing them after…

Sorting lists with multiple tie breakers

I have data in an array like so: I want to sort it by the amount of non-10 values, and I also want to sort it in ascending order for rows, and in descending order of number of 10s: Output: I want to implement a tie breaker system so that if the amount of 10s the same, it now orders

How do i convert a modified list of The Alphabet into a number?

i want to convert the sentence from variable (salam) into numbers. The conversion table is like a modified alphabet just like in (char2). My expected output is a 3×3 matrix, inside is the converted number from(salam) using (char2) and the output is here is the image for clarity Answer The problem is from…