All Questions
34,418
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
77
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 = ...
-2
votes
0
answers
61
views
How can Flat sequences occupy more memory than container sequences in Python? [duplicate]
Fluent python book describes two types of sequences: Container and Flat, with container sequences being able to hold items of different types but as reference to python objects, while flat sequences ...
-3
votes
0
answers
39
views
cannot reshape array of size 1000 into shape (100,100) [closed]
>>> cent_rand = np.random.randint(1919, 3946, 1000)
>>> len(cent_rand)
1000
>>> two_d_cent = cent_rand.reshape((100,100))
Traceback (most recent call last):
File "<...
0
votes
2
answers
60
views
How to process this text?
I have a text file that contains these lines and I'm not exactly sure what's the best way to use Python to load into separate key:value pairs.
dummy-test-foo,rsa,4096,[DNS.1:dummy-test,DNS.2:dummy-...
-3
votes
0
answers
28
views
Repeated indexes in list - Python [duplicate]
I have a long list, that is read from .csv file and it goes like this:
frequency = [..., 398, 399, 398.8, 400, ...]
and so on...
I need to find index for each value, but if the frequency value ...
-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
104
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
votes
0
answers
23
views
How to take two input arrays from user in python? [duplicate]
I would like to take two input arrays from user in python.
Like:
arr1 = [1, 2, 3, 4, 5]
arr2 = [2, 3, 8, 9]
How to take two input arrays from the user?
How to take two input arrays from user in ...
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, ...