Skip to content
Advertisement

Tag: numpy

NumPy: function for simultaneous max() and min()

numpy.amax() will find the max value in an array, and numpy.amin() does the same for the min value. If I want to find both max and min, I have to call both functions, which requires passing over the (very big) array twice, which seems slow. Is there a function in the numpy API that finds both max and min with

How can I make a python numpy arange of datetime

I have some input data, with timestamps in the input file in the form of hours from the date time specified in the filename. This is a bit useless, so I need to convert it to python datetime.datetime objects, and then put it in a numpy array. I could write a for loop, but I’d like to do something like:

How can I check whether a numpy array is empty or not?

How can I check whether a numpy array is empty or not? I used the following code, but this fails if the array contains a zero. Is this the solution? Answer You can always take a look at the .size attribute. It is defined as an integer, and is zero (0) when there are no elements in the array:

Adding row/column headers to NumPy arrays

I have a NumPy ndarray to which I would like to add row/column headers. The data is actually 7x12x12, but I can represent it like this: where A is my 2x6x6 array. How do I insert headers across the first row and the first column, so that each array looks like this in my CSV output file? What I have

python numpy split array into unequal subarrays

I am trying to split an array into n parts. Sometimes these parts are of the same size, sometimes they are of a different size. I am trying to use: This works fine when size divides equally into the list, but fails otherwise. Is there a way to do this which will ‘pad’ the final array with the extra ‘few’

Advertisement