Inside the setup.py script I need to create some temporary files for the installation. The natural place to put them would be the “build/” directory. Is there a way to retrieve its path that works if installing via pypi, from source, easy_install, pip, …? Thanks a lot! Answer By default distutils create build/ in current working dir, but it can
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:
Efficiently accumulating a collection of sparse scipy matrices
I’ve got a collection of O(N) NxN scipy.sparse.csr_matrix, and each sparse matrix has on the order of N elements set. I want to add all these matrices together to get a regular NxN numpy array. (N is on the order of 1000). The arrangement of non-zero elements within the matrices is such that the resulting sum certainly isn’t sparse (virtually
Cartesian product of x and y array points into single array of 2D points
I have two numpy arrays that define the x and y axes of a grid. For example: I’d like to generate the Cartesian product of these arrays to generate: In a way that’s not terribly inefficient since I need to do this many times in a loop. I’m assuming that converting them to a Python list and using itertools.product and
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
How to convert a NumPy array to PIL image applying matplotlib colormap
I have a simple problem, but I cannot find a good solution to it. I want to take a NumPy 2D array which represents a grayscale image, and convert it to an RGB PIL image while applying some of the matplotlib colormaps. I can get a reasonable PNG output by using the pyplot.figure.figimage command: Although I could adapt this to
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’
Indexing with boolean arrays into multidimensional arrays using numpy
I am new to using numpy and one thing that I really don’t understand is indexing arrays. In the tentative tutorial there is this example: I have no idea why it does that last thing. Can anyone explain that to me? Thanks! Answer Your array consists of: One way of indexing it would be using a list of integers, specifying