Skip to content
Advertisement

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 and third dimension. In each step

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 afterwards. There has to be

Why are python dates such a mess and what can I do about it?

A common source of errors in my Python codebase are dates. Specifically, the different implementations of dates and datetimes, and how comparisons are handled between them. These are the date types in my codebase You can print them to see: Is there a canonical date representation in Python? I suppose x7: datetime.date is probably closest… Also, note comparisons are a

Optimize conversion of numpy ndarray to string

I am currently doing a python program to convert from image to hex string and the other way around. I need two functions, one that takes an image and returns a hex string that corresponds to the RGB values of each pixel, and another function that takes a hex string, two ints, and generates a visible image of that size

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 salam.lower. It should be salam.lower(). Without the

Advertisement