Skip to content

Tag: arrays

np.where for 2d array, manipulate whole rows

I want to rebuild the following logic with numpy broadcasting function such as np.where: From a 2d array check per row if the first element satisfies a condition. If the condition is true then return the first three elements as a row, else the last three elements. A short MWE in form of a for-loop which I wan…

Iteratively apply a function to an array

I want to create an array that contains g^0, g^1, g^2…. up to g^100 but all to mod50 (apologies if anyone knows how to format this so the powers are properly aligned I need a bit of help!) In my case g = 23, so I would want an array that looks like: I’ve included all my (incorrect) code at

Add in-between steps into array of numbers (Python)

I am looking for some function that takes an input array of numbers and adds steps (range) between these numbers. I need to specify the length of the output’s array. Example: Result: Is there something like that, in Numpy for example? I have a prototype of this function that uses dividing input array in…

Compare values within a certain timeframe in arrays

I am trying to compare values (0’s and 1’s) in a array. I want to search for each “1” that appears in one column, for another “1” in the other column in a specific timeframe (for example, 5 seconds, 10 seconds, etc.). I will call the 1’s as “signals”. In e…