All Questions
19,899
questions
1
vote
1
answer
71
views
How do I effectively compute pairwise quantities in numpy?
I want to compute pairwise quantities, e.g. distances between two points.
A simple example would be
import numpy as np
N = 9
x = np.linspace(0,1,N)
y = np.abs(x - x[:,None]) # pairwise 1d eucdlidian ...
0
votes
2
answers
68
views
How to transform nested arrays by extending the dimension of the array
Suppose I have an array X with N elements. I would like then to input this array into a 2D array A as follows
X=np.array([0,1,2,3],dtype=np.float64)
A=np.array([[0,0,X],
[0,X,0]],dtype=np....
5
votes
3
answers
75
views
Apply permutation array on multiple axes in numpy
Let's say I have an array of permutations perm which could look like:
perm = np.array([[0, 1, 2], [1, 2, 0], [0, 2, 1], [2, 1, 0]])
If I want to apply it to one axis, I can write something like:
v = ...
1
vote
0
answers
54
views
Copying differently contiguous arrays vs same contiguity arrays
I'm observing different speeds on different machines, but couldn't reason why. Please help me find the reason behind this and how one can handle this difference in performance-critical code - running ...
-5
votes
1
answer
58
views
An ordinary numpy array produces a type error? [closed]
Could someone explain why I get this warning
<>:18: SyntaxWarning: list indices must be integers or slices, not tuple; perhaps you missed a comma?
and this error message
TypeError ...
1
vote
0
answers
84
views
Python Iterating over Numpy Tile and for-loops
Goal: Here is a sample of a dataset that has "ID", "PHASENAME", "CDAYS", "MULTI_FACTOR", "DAY_COUNTER", and "DAILY_LABOR_PERCENT". I was ...
2
votes
3
answers
96
views
How to efficiently compute running geometric mean of a Numpy array?
Rolling arithmetic mean can simply be computed with Numpy's 'convolve' function, but how could I efficiently create an array of running geometric means of some array a and a given window size?
To give ...
2
votes
4
answers
160
views
How to quickly find the minimum element to the right for every element of a Numpy array?
Let's say I have an array:
a = [1,4,3,6,4]
I want to get an array where for every element I have the smallest value in a to the right (inclusive). That is, for a, I would want to create an array:
[1,...
5
votes
3
answers
103
views
What could be the fastest way to build an array of sequence ordered list with numpy?
Say that we start with this situation:
blue numbers correspond to index of the position
This was generated by using this script:
# u v parameters allow to define how many points according to x and y
...
1
vote
0
answers
48
views
Python: How to slice a 2d array to specified range of x and y values? Also how to improve this code?
I have a meshgrid given by X and Y of unequal length and a 2d array of values vx2. I want to create a sub-2d array Z from a certain xlim and ylim. I want to create a contour plot but since matplotlib ...
2
votes
2
answers
75
views
Why is Numpy converting an "object"-"int" type to an "object"-"float" type?
This could be a bug, or could be something I don't understand about when numpy decides to convert the types of the objects in an "object" array.
X = np.array([5888275684537373439, ...
0
votes
3
answers
69
views
Appropriate applications for the as_strided function
I am practicing on figuring out how to use the as_strided function in numpy. I began with the following example of my own where I generate 5 images of 3 x 3 where each image is full of 1s, the next ...
-1
votes
1
answer
39
views
How to get python 2d numpy arrays of shape 2x2 from 4 1d arrays
Suppose I have 4 component arrays of size 6 (e.g., denoting 6 spatial locations in a grid):
Sxx = array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
Sxy = array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6])
Then assume Syx = ...
0
votes
1
answer
37
views
Difference between np.[type] class and np.dtype class
What is the difference between np.[type] class (e.g. np.int8) and np.dtype class?
Some interesting experiments:
>>> import numpy as np
>>> x = np.int8(8)
>>> type(x)
<...
1
vote
1
answer
51
views
Mean over two consecutive elements of array [duplicate]
I would like to compute the mean of two consecutive elements of a python array, such that the length of the final array has the length equal to that of the original array minus one (so something like ...