Questions tagged [python]

A general purpose high-level programming language that emphasizes ease of code syntax and readability.

Filter by
Sorted by
Tagged with
5
votes
1answer
280 views

Meaning of “-0.0” in Python?

We are finding in Python some occasional errors in our coordinate transforms and other similar computations that produce a result of "-0.0". What purpose does this serve in Python? So far it ...
0
votes
0answers
30 views

Merge N number of euclidean distance matrices to get overall single euclidean distance matrix

I want to find out the aggregated euclidean distance of a big dataset D comprising of x and y cordinates where the data set is divided into N sub dataset where 1st sub dataset contains 1 to kth ...
-1
votes
0answers
29 views

Python approach for calculating a 2D matrix by interpolating 'between' two other 2D histograms

I have two 2D histograms, A and B, calculated from simulations by changing a single input parameter (alpha and beta set at "5" and "7", respectively). I want to calculate a third ...
1
vote
1answer
38 views

Efficiency of scipy.sparse.linalg.expm_multiply with sparse vs unsparse vectors

From the package scipy.sparse.linalg in Python, calling expm_multiply(X, v) allows you to compute the vector ...
3
votes
0answers
45 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
0answers
45 views

Simulation data from VTK to python

I have run some simulations that give the output data in the VTK format. This is very nice for visualization in Paraview. However, I want to take some spatial Fourier transforms of the data in the VTK ...
2
votes
1answer
137 views

Convolute a gaussian kernel with a large array of off-grid centroids without looping? (how to make “A Thousand (Gaussian) Points of Light” )

For a finite object size diffraction simulator, I need to generate arrays which are the sum of thousands of instances of a Gaussian (or other) 2D kernel at centroids that will not fall in any ...
1
vote
0answers
65 views

How to generate the convolution of f(x, y) with a parametric function g(t), x(t), y(t) in Python? (Something better than this brute-force sum)

I'd like to know how to convolute $f(x, y)$ with a parametric shape; a 1D distribution along a parametric path as defined by $g(t), \ x(t), \ y(t)$ in Python, resulting in a 2D array of $f * g$. A ...
-1
votes
0answers
19 views

Solve_ivp using timestep

I am trying to compute the path of a charged particle as it moves through a magnetic field. I am currently using a uniform field, but I am going to expand into nonuniform fields later on. The problem ...
-2
votes
0answers
24 views

Integrating an array of ODEs

The system I am dealing with is a compartmentalized model, each compartment having 4 ODEs describing the dynamics of the variables inside, and each ODE also having terms connecting variables across ...
1
vote
1answer
67 views

Numerical solution to the infinite well problem

I've used the following code to implement it ...
-1
votes
1answer
95 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 ...
-1
votes
0answers
14 views

Generate random functions following certain constrains (Using python)

How to produce random functions $g:N\times N\rightarrow N$ where $N=\{ 0,1,\ldots ,n \}$ and $$g\Big( g(a,b)\; ,c\Big)=g\Big(a,\; g(b,c)\Big)\quad \forall a,b,c\in N \qquad \text{[Constraint of ...
0
votes
0answers
134 views

Do the projection (with Jacobian) and marginalisation (inversion of matrix and remove a row/column and reinversion) commute?

I try to check the equality or the inequality between 2 Fisher matrices. The goal is too see if the projection (with Jacobian) and marginalisation (inversion of matrix and remove a row/column and ...
-1
votes
1answer
77 views

Fitting using curve_fit of scipy in python gives totally different answer for 1/t and t

I was trying to fit some data to a single degree exponential decay function but a*exp(-x*t) and a*exp(-x/t) gives completely ...
0
votes
1answer
50 views

Trying to do a 2D random walk for a particle

I am trying to perform a two-dimensional random walk for a particle, but I am not getting the desired result. The plot produced is a linear plot, which obviously should not have been. Similar code for ...
0
votes
2answers
52 views

Passing in user inputs with mpirun

I am building a quantum circuit simulator using mpi4py. The simulator takes user inputs to build the initial system and quantum gates the system passes through. I can get the code to work if I do not ...
-2
votes
2answers
86 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{...
0
votes
0answers
70 views

How to distinguish primary hosts (stars) and orbiting satellites (planets) and tertiary bodies (moons) by their mass and trajectory?

I posted this question in the astronomy stackexchange. There are no responses, and it was suggested that I pose the question here. The "too long, didn't read" was taken from a comment, and ...
-1
votes
1answer
127 views

Generate 3D “matrix” with Pandas, based on comparing two dataframes [Python]

Good morning everyone. I am working with Python and Pandas. I have two DataFrames, of the following type: ...
0
votes
0answers
21 views

Why does this Non-Standard FDTD implementation lead to infinite increase in the magnitude of an EM pulse?

I have been working on a Particle-In-Cell Framework in Python and have noticed an issue where the magnitude of a EM pulse increasing infinitely as the simulation updates. Currently, I am using the Non-...
1
vote
0answers
38 views

Ising model in Python (Magnetization Scaling)

I am trying to implement the Ising Model in Python for Gibbs Distribution: $$\pi(x) = \frac{1}{Z(\beta)} e^{-\beta H(x)}$$ \begin{align*} p(x,y)&=r(x,y) \cdot \min \left( \frac{\pi(y)}{\pi(x)},1 \...
-1
votes
1answer
67 views

In a random walk simulation, how do I get the mean and standard deviation of how many times the walk returns to the origin?

So I'm simulating a 1-dimensional random walk, with 1000 walks that each take 1000 steps. How do I calculate the average number of times that a walker returns to the origin and then the standard ...
2
votes
1answer
144 views

How is the fuzzy logic calculated in scikit-fuzzy?

I am following this example from documentation of scikit-fuzzy library, but cannot figure out the math behind fuzzy rules there. Here is a short version of the ...
0
votes
0answers
32 views

Vector Form Using the Curl (Line Integral ) in Python

There is an example in Vector Calculus from Madsen & Tromba page 435 that states: Let $F=(xy^2,y+x)$.Integrate $(\nabla \times F)\cdot k$ over the region in the first quadrant bounded by the ...
0
votes
1answer
40 views

Question about scipy’s ivp solver

there is one thing I don’t understand. Is the tolerance to compute the step size updated at each timestep or fixed at all timestep. Also, when we look at the documentation and how the tolerance is ...
2
votes
1answer
139 views

Solving numerically the 1D Kuramoto-Sivashinsky Equation using spectral methods

Lately, I've been trying to solve numerically the 1D Kuramoto-Sivashinsky Equation using spectral methods. Let $\nu$ be the viscosity and $[0,L]$ the domain. The 1D equation is, $$ u_t + uu_x + u_{xx} ...
2
votes
3answers
158 views

Solving a PDE with 2 variables, with one variable whose derivative with respect to space is only known

I am trying to solve a PDE of the form $$\frac{\partial u}{\partial t} = D \frac{\partial^2u}{\partial x^2} + k\ \ \ (1)$$ where only $k$'s first derivative with respect to $x$ is known $$\frac{\...
2
votes
1answer
65 views

Solving the 2D Rectangular Waveguide PDE with a Neumann boundary condition for TE modes

I am trying to find the possible modes of a 2d rectangular waveguide by solving the equation, $$\Big(\frac{\partial^2}{\partial x^2} + \frac{\partial^2}{\partial y^2} + \gamma^2 \Big)\psi = 0$$ where $...
2
votes
4answers
148 views

Eigenvalue decomposition for a very huge matrix of medical images (such as the pixel physical coordinates of CT images)

I am trying to do eigenvalue decomposition for a huge matrix larger than 788000×788000 for medical image analysis. The matrix is not sparse and every element in the matrix has a real value. And, for ...
0
votes
1answer
174 views

Pseudospectrum of non square Matrix in Python

I have a rectangular matrix $A \in \mathbb{R}^{m \times n}$ ...
3
votes
0answers
27 views

Unexpected CUDA processing time dependency on thread count [closed]

When calling a kernel function, the number of threads per block should ideally be a multiple of the warp size. This yields more efficient use of resources and lower processing times. However, there ...
3
votes
1answer
94 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
0answers
38 views

How to efficiently perform this 2D integral in Quadpy?

I need to integrate a function defined in 2Dims (z and radius r), for which I don't have an expression. I can just query the ...
-1
votes
1answer
36 views

Generating Rvs for a given PDf in python

Two random variables $X$ and $Y$ are distributed according to \begin{align} f_{XY}(x,y)= \begin{cases} x+y & 0\leq x \leq 1, 0\leq y \leq 1 \\ 0 & otherwise \end{cases} \end{align} I ...
0
votes
0answers
109 views

Numerical Range of a matrix in Python

In the mathematical field of linear algebra and convex analysis, the numerical range or field of values of a complex $n\times n$ matrix $A$ is the set $$W(A)=\left\{{\frac {{\mathbf {x}}^{*}A{\...
0
votes
1answer
120 views

Error using scipy.integrate.solve_ivp: index error: the index 0 is out of bounds for axis 0 with size 0

I am recently working on the code based on the stick-slip phenomenon in Python. It's the stick-slip oscillator (chapter 3.4) in https://www.sciencedirect.com/science/article/pii/S0888327020301205. And ...
0
votes
1answer
169 views

N-body problem with differents solvers (RK2, RK4, Euler symplectic, Stormer-Verlet) : planets drift to infinity

I'm trying to write an integrator for the 2 and 3-body problem. I choose to start from a generalisation to N-body problem so I can just pass my bodies to the same integrator in the two cases. I'm ...
0
votes
0answers
36 views

Newton-Raphson for estimating Weibull distribution does not converge

I've been trying to estimate the two-parameter (a,b) Weibull distribution (loc. param. = 0). $$f(t;a,b)=\frac{b}{a}\left(\frac{t}{a}\right)^{b-1}\exp(- \left(\frac{t}{a}\right)^b) $$ To find the ...
2
votes
0answers
69 views

Errors in Integral Estimate of Gaussian using Trapezoidal Rule

I'm trying to estimate the percentage error in computing the integral of a Gaussian via composite trapezoidal rule versus via an exact formula. To do this I've generated a gaussian with mean 0, ...
0
votes
1answer
68 views

High Running Time and Suboptimal Accuracy of 2D Wave Equation Solver with Finite Differences

Im trying to solve the following 2D wave equation: $$u_{tt} = u_{xx} + u_{yy}, \hspace{3mm} u(x,y,0) = \cos(4 \pi x) \sin(4 \pi y), \hspace{3mm} u_t(x,y,0) = 0$$ with the periodic boundary condition ...
1
vote
1answer
39 views

Looping in Python to find additional vectors using a given initial condition

My question relates to looping in Python. I have an original $6$-sized vector, $F(n,t=0)=[1,0,0,0,0,0]$ Hence, the $n$-values range from $0 \rightarrow 5$. This output for the original vector is just ...
2
votes
2answers
121 views

Generating particles from a distribution function using Monte Carlo

I have been given a 4D ($x, y, v_x, v_y$) distribution function, $f(x,y,v_x, v_y)$, generated by an external code. I want to generate a set of particles from this distribution function, say 10k ...
2
votes
0answers
63 views

Divergence on wave equation simulation

I'm currenly working on my own PDE solver for non-linear simulations in python. I've done succesfully simulations for KdV and Fisher's equation, but now I'm playing with second order derivatives in ...
-1
votes
1answer
71 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 ...
-1
votes
1answer
99 views

Implementation of Source Panel Method as Described in Katz Plotkin Book

I am currently trying to implement Source Panel method as described in Katz and Plotkin in Low Speed Aerodynamics. I have successfully implemented two previous methods. However, I am fully blocked on ...
3
votes
2answers
357 views

CUDA & Python for numerical integration and solving differential equations

Can anyone please suggest some libraries which allow use CUDA in Python for numerical integration and/or solving of differential equations? My goal is to solve large (~1000 equations) of coupled non-...
0
votes
0answers
80 views

1D Poisson equation and quadratic basis functions assembly

I'm solving the simple Poisson problem $$-u''(x)=1$$ in the interval $[0,1]$ with $u(0)=u(1)=0$. I discretised my domain as done here, i.e. with ...
1
vote
1answer
93 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 ...
3
votes
0answers
50 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: ...

1
2 3 4 5
15