All Questions
34,433
questions
0
votes
0
answers
22
views
Why does `blake2b` on a `numpy` array give different results in different machines?
I ran the following code in two different machines:
import numpy as np
from hashlib import blake2b
print(blake2b(np.array([1, 2, 3])).hexdigest())
The two machines print a different result. Why ...
-7
votes
1
answer
57
views
WiggleSort: giving wrong output? [closed]
I am trying to solve LeetCode problem 324. Wiggle Sort II:
Given an integer array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....
You may assume the input array always ...
0
votes
0
answers
18
views
Plotting Eigen-energies using QuTip
I am trying to plot the eigen-energies of the following Hamiltonian
$$ H = 2\tau \cos(\frac{eA}{hc} \sin(\omega t) + k) $$
Here \tau value is set to 1. A is the amplitude. e,h,c are electron charge, ...
0
votes
0
answers
15
views
pLotting the correlation between temperature and wildfire in iran
The idea is to find the correlation between wildfires and temperature in iran.
I used the coordinate for each wildfire against the temperature in iran, i mean the geometry but the p-value was very low ...
0
votes
3
answers
69
views
numpy 2d arrays, remove duplicate rows
I have 2 2d numpy arrays, Array A and Array B.
I want to remove rows who occurs in both arrays for Array A and B.
But, if it occurs 1 time in Array A and 2 times in Array B, I want to only remove it 1 ...
1
vote
1
answer
36
views
Iteration of a graph approximation
The code below runs a model based on a graph generated by the solution to a system of differential equations and shows one with random 5% error added to the points. How would I iterate this process (...
4
votes
2
answers
57
views
Numpy: apply mask to values, then take mean, but in parallel
I have an 1d numpy array of values:
v = np.array([0, 1, 4, 0, 5])
Furthermore, I have a 2d numpy array of boolean masks (in production, there are millions of masks):
m = np.array([
[True, True, ...
0
votes
3
answers
62
views
python and problems with passing array to a function
I need to solve some ordinary differential equation dy/dx = f(x) = x^2 ln(x) and to proceed I create the array xpt between the limits 0. <= xpt <= 2. Because I have to be careful at xpt = 0, I ...
-1
votes
0
answers
46
views
Dividing number into minimum number of teams
I am trying to solve a problem. There are 2 possible team sizes teamSize1 and teamSize2, and p total players. How can we divide the players such that each player is in exactly one team, and the number ...
0
votes
0
answers
56
views
How do I build a specific Python structure of a 2D array of 1D arrays?
How do I build a specific structure of a 2D array of 1D arrays (i. row vectors) to meet the specific
structure of a legacy programme I am maintaining?
I can generate the right content, in this ...
4
votes
0
answers
104
views
Why is np.sort() with order slow on multi dtype arrays? (sorting by unsigned integer ID)
Working with embedded software, I'm using numpy arrays with specified datatypes to save memory and other reasons. I'm using version '1.23.4' and Python 3.10.0, but this seems to be an issue with ...
1
vote
1
answer
74
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
70
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
2
answers
84
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
76
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 ...