I have a cubic grid as shown in the picture below. I would like to list the vertices of each sub-cube, so I would end up with a nested list of sub-cubes with their corresponding list of vertices. My initial attempt was to use a generator, This does give me the desired shape but coordinates are ordered in a manner
Tag: numpy
numpy second derivative of a ndimensional array
I have a set of simulation data where I would like to find the lowest slope in n dimensions. The spacing of the data is constant along each dimension, but not all the same (I could change that for the sake of simplicity). I can live with some numerical inaccuracy, especially towards the edges. I would heavily prefer not to
Convert a numpy.ndarray to string(or bytes) and convert it back to numpy.ndarray
I’m having a little trouble here, I’m trying to convert a numpy.ndarray to string, I’ve already done that like this: It works, but I’m wondering if I can transform it back to a numpy.ndarray. What’s the best way to do this? I’m using numpy 1.8.1 Context: The objective is to send the numpy.ndarray as a message in rabbitmq (pika library)
Computing the correlation coefficient between two multi-dimensional arrays
I have two arrays that have the shapes N X T and M X T. I’d like to compute the correlation coefficient across T between every possible pair of rows n and m (from N and M, respectively). What’s the fastest, most pythonic way to do this? (Looping over N and M would seem to me to be neither fast
Implement MATLAB’s im2col ‘sliding’ in Python
Q: How to speed this up? Below is my implementation of Matlab’s im2col ‘sliding’ with the additional feature of returning every n’th column. The function takes an image (or any 2 dim array) and slides from left to right, top to bottom, picking off every overlapping sub-image of a given size, and returning an array whose columns are the sub-images.
How to get a list of all indices of repeated elements in a numpy array
I’m trying to get the index of all repeated elements in a numpy array, but the solution I found for the moment is REALLY inefficient for a large (>20000 elements) input array (it takes more or less 9 seconds). The idea is simple: records_arrayis a numpy array of timestamps (datetime) from which we want to extract the indexes of repeated
Sum slices of consecutive values in a NumPy array
Let’s say I have a numpy array a containing 10 values. Just an example situation here, although I would like to repeat the same for an array with length 100. I would like to sum the first 5 values followed by the second 5 values and so on and store them in a new empty list say b. So b
Set numpy array elements to zero if they are above a specific threshold
Say, I have a numpy array consists of 10 elements, for example: a = np.array([2, 23, 15, 7, 9, 11, 17, 19, 5, 3]) Now I want to efficiently set all a values higher than 10 to 0, so I’ll get: [2, 0, 0, 7, 9, 0, 0, 0, 5, 3] Because I currently use a for loop, which is
Ordered Logit in Python?
I’m interested in running an ordered logit regression in python (using pandas, numpy, sklearn, or something that ecosystem). But I cannot find any way to do this. Is my google-skill lacking? Or is this not something that’s been implemented in a standard package? Answer Update: Logit and Probit Ordinal regression models are now built in to statsmodels. https://www.statsmodels.org/devel/examples/notebooks/generated/ordinal_regression.html Examples are
How do I bin and categorize numbers in Python?
I’m not sure if binning is the correct term, but I want to implement the following for a project I am working on: I have an array or maybe a dict describing boundaries and/or regions, for example: The areas are indexed from 0 to 100 (for example). I want to classify each area into a color (that is less than