Questions tagged [numpy]
NumPy is the fundamental package for scientific computing with Python.
159
questions
0
votes
1
answer
71
views
Compute a series of matrix multiplications and matrix norms quickly in Python
I need to compute a series of matrix multiplications involving 3x3 matrices and a series of matrix norms also involving 3x3 matrices and I wonder how I can set these computations up with numpy such ...
0
votes
0
answers
69
views
3
votes
1
answer
159
views
Time and memory required to diagonalize a 18000 by 18000 matrix using numpy in python
Can someone give an estimate of the Time and memory required to diagonalize a 20000 by 20000 complex hermitian matrix using numpy in python ?
0
votes
1
answer
194
views
Specifying mesh spacing for DFT in numpy
I was testing the .fft package of numpy 1.16.1 in Python 3.7.2. In particular I was trying to verify that the transform resembles the analytical one for: $$f(x) = \mathrm{exp}\left[-\left(\frac{x-5}{2}...
1
vote
0
answers
70
views
Convolution/weighted average of two arrays in Python
I have an equation that I need to calculate numerically, but I am having doubts about my approach. I am cross-posting this question from Stack Exchange, because I am not getting any responses.
This is ...
0
votes
0
answers
54
views
Eigenvalues of same operator expressed in two different orthonormal basis are coming out different
I have an operator $H$. I express $H$ as a matrix in the orthonormalized $\{ |e > \}$ basis. Then I diagonalize it to obtain eigenvalues, let's say for example $H$ is $6 \times 6$ and the ...
1
vote
1
answer
256
views
Beta function and integral value
I have two values $a$ and $b$ where $a \ge 0$ and $b \ge 0$ and I have to calculate the formula below.
$$
\frac{1}{2}\int_0^1\text{abs}\left[\left( \frac{p_i^{(a - 1)} \times (1 - p_i)^{(b - 1)}}{\...
0
votes
1
answer
109
views
How to convert from a non traditional CSV-style content (file with JSON data but its extension is .CSV) to a traditional CSV-style with Python?
CSV (even though once opened it does not contain a traditional CSV format I think it contains JSON data)[![1], when I try to open it as a TXT file I got this as shown in the first screenshot. When I ...
0
votes
1
answer
134
views
Find two lines around which points were randomly generated
Given a list of points that were randomly generated around two lines, find two new lines that match the original lines as closely as possible. Here's the function definition:
...
0
votes
1
answer
70
views
Planes in n-dimensional space
This is not a homework, but a hobby project, and maybe not all terms I use are correct - please help to fix.
Imagine there are K vectors in n-dimensional space. I would like to:
validate whether they ...
2
votes
0
answers
93
views
How to save multiplication computation time between a dense vector and a not that sparse matrix?
I am trying to compute $\mathbf{X}\mathbf{u}$ for many times in my algorithm, where $\mathbf{X}\in \mathbb{R}^{n\times m}$ and $\mathbf{u} \in \mathbb{R}^{m}$. The problem is that, during the ...
8
votes
3
answers
18k
views
plotting discontinuous functions
I need help plotting the Heaviside function:
Real analysis often involves constructing bizarre functions which are intuitively correct, but ultimately wrong. See the great book Counterexamples in ...
0
votes
0
answers
83
views
Advance a Interpolation
Note; No special knowledge of Pykrige is needed to answer the question, as I already mention examples in the question!
Hi I would like to use Universal Kriging in my code. For this I have data that ...
2
votes
0
answers
278
views
How can I reduce the artifact in "Thin Plate Spline" interpolation?
At the Top "right", there is the 2D-density plot of the recorded data
(actual), fewer in number. Recorded data has been sampled a on the 8
arms of a regular octagon. These 8 arms are placed ...
-1
votes
1
answer
108
views
Fitting gauss-hermite-parametrization to data?
I want to fit this data.
I have the following model functions. Classic gaussian:
def gauss_model(x, mu, sigma):
return np.exp(-0.5*((x-mu)/sigma)**2)
And ...
5
votes
1
answer
2k
views
Rational functions in Python
I would like use Python to verify the following identities:
$ \frac{1}{1-z} = 1 + z + z^2 + z^3 + \dots $
$ \frac{1}{1-z - z^2} = 1 + z + 2z^2 + 3z^3 + \dots $
$ q \prod_{n \geq 1} (1 - q^n)^{24} = ...
4
votes
0
answers
159
views
How amenable is this 2D Frenkel–Kontorova-like energy minimization problem in Python to the use of a modest PC + GPU? (Heavy reliance on indexing)
@Richard's answer to Going to try to move some of my scipy/numpy calculation to a new GPU, how to avoid disappointing results? is quite helpful, and as promised I've added a simple running example ...
1
vote
1
answer
55
views
Why does this implementation for Eisenstein integer pairs of Euclid's method for finding greatest common denominators get stuck for this one point?
My Math SE question determining if a coincident point in a pair of rotated hexagonal lattices is closest to the origin? explains the problem I have. I won't reproduce the whole thing in detail here, ...
5
votes
1
answer
575
views
Stochastic SIR using SDEint python package
I want to use the SDEint package to give a numerical solution (plot) of the following stochastic SIR model. Namely, a system of SDEs.
$$\begin{cases}
dS = -\beta SIdt - \sigma SIdW \\
dI = (\beta SI -...
4
votes
1
answer
348
views
Going to try to move some of my scipy/numpy calculation to a new GPU, how to avoid disappointing results?
update: I've refactored the question based on helpful advice in the linked meta.
I'm a heavy user of Python's NumPy and SciPy (and not much else) and for years I could run anything I need on my laptop....
1
vote
0
answers
182
views
Trouble inverting complex matrix with numpy and scipy
I have some matrix-valued, complex data $Z(f)$ with $f\in\{f_0,f_1,\dots\}$ and $Z(f_i)$ being a 3x3 matrix. I require the inverse $Z^{-1}(f)$ in my workflow. After encountering some problems with my ...
5
votes
0
answers
98
views
How to troubleshoot numerical instability using finite difference for steady-state non-linear heat conduction equation
I have a problem which I believe is numerical instability when trying to solve a heat conduction equation using finite difference. The short version is that when the parameter $I=80.3$ I get the blue ...
2
votes
2
answers
262
views
Calculate determinant of unitary matrices based on SVD implementation
I have a real square matrix $X$ which I need to perform a Singular Value Decomposition on. Now, performing the operation
$$
X = USV^T
$$
as $U$ and $V$ are orthogonal, we know that $\det(X)=\pm\det(S)$...
13
votes
1
answer
1k
views
Fast Automatic Differentiation for numpy?
I would like to use automatic differentiation to calculate gradients to function written in numpy.
I've come across a number of packages, including
autograd
tangent
chainer
But none of them seem ...
0
votes
2
answers
568
views
Is it possible to partition 2D data into bins such that each bin contains the same number of samples?
I am trying to sort data following a bivariate distribution into a numpy histogramdd, where each bin should contain the same number of data points (to the nearest whole sample).
I expect that some ...
2
votes
1
answer
2k
views
solve_ivp from scipy does not integrate the whole range of tspan
I'm trying to use solve_ivp from scipy in Python to solve an IVP. I specified the tspan ...
0
votes
2
answers
130
views
Implementation of $[X, \cdot]$ as an $n^2 \times n^2$ matrix, where $X$ is an $n \times n$ matrix
Let $M_n(\mathbb{R})$ denote the set of $n\times n$ matrices with real entries. I have an $n\times n$ matrix $X\in M_n(\mathbb{R})$, and I would like to implement the linear operator $[X, \cdot] : M_n(...
0
votes
0
answers
141
views
Getting euclidean distance between vector A and C without anyway of retrieving them when their distances with a common vector B is known
Motivation:
My plan is to get the overall euclidean distance matrix for all the vectors in N number of dataset. Each dataset is basically an array of n-dimensional points. For e.g: A dataset can be ...
0
votes
0
answers
101
views
Plotting the motion of a positive charge in a cylindrically symmetric magnetic field
I want to plot the motion of a positive charge in a cylindrically symmetric magnetic field.
I am assuming a cylinder around the z-axis, with the magnetic field going in clockwise direction. The B-...
1
vote
1
answer
1k
views
Reason behind different outputs for Fast Fourier Transform in Numpy and Matlab
Here is the output of Numpy
np.fft.ifft([0, 4, 0, 0])
array([ 1.+0.j, 0.+1.j, -1.+0.j, 0.-1.j]) # may vary
Here is the output of Matlab
...
4
votes
0
answers
134
views
Solving multiple linear regression in parallel
I am working on a problem where I need to solve approximately 500 Million Linear Regressions (OLS).
What would be the most efficient way to do this (e.g. using GPU or a some framework that can do this ...
-1
votes
1
answer
495
views
Using ODE to plot particle-motion with scipy.integrate.solve_ivp
My Problem:
A positively charged particle (mass = 2 * 10-27 kg) is moving along the x-axis. It is travelling in a homogenous magnetic field such that the field axis in z-direction. The energy of the ...
-2
votes
2
answers
199
views
numerical solution for differential equation
I have these 3 equations and i want to solve them with numerical methods. so I am using scipy library but I don't know how to solve 3 equations together.
R, g, sigma and density are constants.
\begin{...
3
votes
1
answer
159
views
Forming a particular (averaged) block matrix with numpy
Say I have a set of $n \times n$ matrices $A_1, ..., A_m$ as numpy arrays. I'd like to create the block matrix defined below.
I'm looking for a clean, elegant, and easy-to-interpret way of doing this ...
1
vote
1
answer
215
views
How do I find the portion of a cell/voxel lying within a defined surface?
We have a 3-dimensional grid of voxels (or cells), with individual voxels being of volume $dx\,dy\,dz$ where $dx=dy=dz=1$.
A cone-like surface is defined by some function, $z = f(x, y)$, which in ...
3
votes
1
answer
243
views
Lanczos algorithm for finding top eigenvalues of a matrix sum
I am trying to find the top k leading eigenvalues of a NumPy matrix (using python dot product notation) L@L + a*X@X.T, where $L$ ...
0
votes
2
answers
92
views
Validating that a code is a good spherical code
Apologies if this is a trivial question. If that is the case I imagine I would benefit from someone explaining where my understanding is lacking.
I am having some trouble interpreting the (putatively ...
-1
votes
1
answer
272
views
illegal use of ODEINT
given the following system:
$$\frac{dP}{dt} = \alpha P(1-\frac{P}{K}) - \beta P I$$
$$\frac{dI}{dt} = \beta P I - \rho I$$
how do I solve the system numerically. as when I attempt to solve this is the ...
3
votes
0
answers
122
views
Difference between wave vector and density matrix in numerical calculation of Schrödinger equation
I solved Schrödinger equation for a following tow-level time-dependent Hamiltonian numerically in two ways:
...
0
votes
1
answer
4k
views
Saving Data in Multiple Columns with np.savetxt
I have managed to write the following code for the following problem:
Projectile's horizontal and vertical displacement are given by:
$$ x = v_0 \, t \cos(\theta) $$
$$ y = v_0 \, t \sin(\theta) - \...
1
vote
0
answers
45
views
Interpolate location based on triangular sensor array
There are 3 sensors (A, B, C) on a plane, located in the corners of a (known) equilateral triangle.
I want to calculate the (2D) location of an object (X) inside that triangle.
One sensor returns one ...
-1
votes
1
answer
145
views
plotting $F=K \frac{q_1 q_2}{r^3}$ in python
I tryin to plot the position of electron in the hidrogen atom by Coulomb's law,
$F=K \frac{q_1 q_2}{r^3}$
This is mi code
...
-1
votes
1
answer
102
views
Solve integral $ \int_{-\infty}^{\infty} e^{-x^2}dx$
i trying to solve this integral
$$\int_{-\infty}^{\infty} e^{-x^2}dx$$
I'm using this
CODE
...
2
votes
1
answer
755
views
How to Invert a Poorly Conditioned Matrix
In my research, I need to invert a Fisher matrix in order to get a covariance matrix for me to do parameter estimation. Unfortunately, the values of Fisher matrix vary by many orders of magnitude, and ...
4
votes
1
answer
657
views
Backwards Difference Implicit Method for Nonlinear Parabolic PDE in Python
Original Stack Overflow Question: https://stackoverflow.com/questions/65683788/indexerror-index-31-is-out-of-bounds-for-axis-1-with-size-31?noredirect=1#comment116218335_65683788
PDE: u_t = u_xx + u(...
0
votes
1
answer
275
views
How to compare 2D vector fields and minimize the difference?
I want to compare the field of two electrical currents and compare the resulting field to a magnetic dipol field and find magnetic momentum that minimizes the difference of the two fields.
My current ...
2
votes
1
answer
397
views
Help with modified bessel functions
I'm trying to parse the following expression (Eq. 35 in The Magnetic Field in the Vicinity of Parallel and Twisted Three-Wire Cable Carrying Balanced Three-Phased Current) in Python and calculate its ...
1
vote
0
answers
64
views
Help with vectorized computation where vector multiplication would need to create an additional dimension
I want to use vectorized computation (with python and numpy) to do some calculation involving bessel functions.
As is often the case, I need to calculate the sums of bessel functions of (infinit) ...
1
vote
2
answers
413
views
The derivative of a gauss function via FFT and IFFT in Python
I have a problem with computing a derivative of a Gauss function using FFT and IFFT from NumPy library. I use the fact that
$$
\begin{equation}
\frac{d}{dx}f(x) = \frac{1}{\sqrt{2\pi}}\int{ike^{ikx}\...
1
vote
0
answers
30
views
Problem with recursive implementation of Subspace Iteration method in Numpy
I am having trouble with implementing the method of subspace iteration to find the eigenvalues and vectors of a random, symmetric matrix, A that is mxm with m = 10. ...