Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [python]

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

2
votes
1answer
281 views

How to broadcast my matrix exponentiation

I'm trying -to no avail- to broadcast the following piece of code in Python: ...
4
votes
4answers
997 views

Practical coding resources for new CFD practicioners

There seem to be many books and papers that explain various CFD methods in great detail, but unfortunately I have not been able to find many good resources of such methods implemented in codes such as ...
1
vote
1answer
59 views

Plotting the same function multiple times on the same set of axes but with different parameters [Python]

I am currently trying to plot a function which describes linear perturbation growth in cosmology for different world models. I would like to be able to have all the curves on the same set of axes, but ...
1
vote
0answers
136 views

How to test for convergence (smoothness of Pareto front) in DEAP

In the DEAP algorithms (see documentation here), I notice that we need to specify the the number of generations (NGEN). I was advised that convergence has been achieved if the Pareto curve is smooth. ...
4
votes
1answer
510 views

1-D incompressible unsteady Couette Flow Explicit finite differece CFD

I am currently following J.Anderson Jr.'s CFD with basic application and I came into some troubles while coding for my very first CFD problem. As the title suggests I am solving an incompressible ...
0
votes
1answer
445 views

What is wrong with this Euler method code in python?

I am testing the ability of my integration method to reproduce results obtained analytically (for various values of the parameters), but the results turn out to be completely wrong and I can't find ...
1
vote
2answers
840 views

stop condition in scipy.integrate.ode for stiff system

I'm using Python scipy.integrate.ode, and I want to stop my integration at a certain condition. So I use the integrator "dopri5" and use the method "set_solout" to specify a function for my stop ...
1
vote
0answers
640 views

Solving an integral equation in Python

I have to solve the following equation for $x(i), 0 \leq i \leq 1$: $$ y(i) = x(i)^{-a} \int_0^1 y(j)x(j) dj \left(\int_0^1 \mathcal A(j) x(j)^{1-a} dj\right)^{-1} \int_i^1 \left( \int_0^x x(j)^{1-a} ...
1
vote
0answers
652 views

Wrong amplitude of convolution using numpy fft

I try to convolve a rectangle function in [-1/2, 1/2] with itself using fft. The convolution should be a tent shaped function, see figure below. The code is below. In the 3rd to last line I add /50 ...
1
vote
1answer
178 views

Efficiently generate a random subgraph (Gs) with maximum degree K, using only edges from an existing graph G

I am looking find a way of efficiently generating a random, undirected subgraph $G_s$ with $N$ vertices, using a subset of edges from an exisiting undirected graph $G$, also of size $N$, where the ...
1
vote
1answer
163 views

Generate paraview plot of an ensight .case without launching the paraview gui

Disclaimer : This question is related to computational science, but it is a purely a post-processing question so if this is on the wrong board, please tell me I would like to postprocess simulation ...
1
vote
0answers
97 views

Integral over reference element in $1$D FEM: how to map the quadrature points?

The following is related to a question a asked a few days back 1, but now I would like to focus on just one part of the problem. I have problems computing the integral over the reference element: $$ ...
4
votes
2answers
167 views

Optimization of known function with respect to two unknown function arguments

I have a data set, composed of points $(x_i, y_i)$ for $i=1,N$. I also have a known function $F$, which maps these points $x_i$ to $y_i$ as such $F(x_i, a(x_i),b(x_i)) = y_i$, where $a(x_i)$ and $b(...
1
vote
0answers
71 views

vectorizing optimization or root finding [closed]

I need to find the roots of a function. I am currently using scipy.optimize.fsolve ...
1
vote
0answers
150 views

Lambdify error when sympy array contains number

This example is a dummy example, but it describes exactly whats goes on in my problem. As a result from some sympy calculation and manipulation i got two arrays ...
3
votes
1answer
575 views

integral including a vector

I need to calculate the integral of this function def f(z): return ((1-2*z)*np.exp(-d/z))/(((1-z)**(2+d))*(z**(2-d))) Here d is a constant. I am using this ...
1
vote
0answers
90 views

vectorizating function integration scipy python

I need to implement the following in python: For a given discrete time series Zt (t=0 to T), find smallest t such that: $c\sum_{s=0}^t e^{[k(Zt-Zs)+m(t-s)]} >= \frac{p*}{1-p*} $ where c,k,m are ...
0
votes
1answer
499 views

Python - Differentiating Cubic Spline numerically or analytically

I'm trying to take data in numpy arrays, interpolate them and retrieve this function to differentiate/integrate at different stages. Here is how I got here, data included: ...
10
votes
3answers
1k views

Are there any “light-weight” FEM packages around?

Basically, FEM seems to be a problem that is pretty much "solved". There are numerous powerful frameworks existing, like Trilinos, PETSc, FEniCS, Libmesh or MOOSE. One thing they have in common: They ...
0
votes
1answer
296 views

Implementing odespy for system of PDEs

After trying to use RK4 to solve the below system of equations, it appears the output had large and fast oscillations even with an adaptive time step I incorporated using the Cash-Karp method. I am ...
8
votes
1answer
539 views

Why does LSODA fail to integrate the logistic function?

I'm comparing some of the different ODE integrators in scipy.integrate.ode on solving the logistic function: $$x(t) = \frac{1}{1+e^{-rt}}$$ $$\dot{x} = rx(1-x)$$ ...
1
vote
0answers
141 views

How to obtain projections from sinogram in ART reconstruction technique?

I'm kind new in the Computed Tomography field and I'm trying to understand and implement ART technique. Said it, I started to read the book The Mathematics of Medical Imaging - A Beginners Guide by ...
2
votes
1answer
2k views

Using backward vs central finite difference approximation

I am solving the simple 2nd-order wave equation: $$ \frac {\partial ^2 E}{\partial t^2} = c^2 \frac {\partial ^2 E}{\partial z^2} $$ Over a domain of (in SI units): $ z = [0,L=5]$m, $t = [0,t_{max} ...
1
vote
0answers
807 views

Finding eigenvectors and eigenvalues of large matrices in Python's numpy

I am running a PCA analysis on a data set using Python's (v2.7.10) NumPy. I validated that my program works by running the PCA analysis on a smaller dataset and then confirming that I get similar ...
2
votes
2answers
775 views

Data corruption when taking gradient of numerical data in python

Question Below is a plot of a graph $y$ and its derivative $dy/dx$ calculated using python's numpy.gradientwhich approximates the derivative with finite ...
0
votes
1answer
340 views

Use of scipy sparse in ode solver

I am trying to solve a differential equation system $$x´=Ax\quad \text{with } x(0) = f(x)$$ in Python, where $A$ indeed is a complex sparse matrix. For now i have been solving the system using the ...
0
votes
1answer
144 views

How to compute matrix representation of $\hat{y}\frac{\partial}{\partial x}$?

I have a 2-dimensional system which I would like to solve numerically (I'm using finite difference method right now), and its an eigenvalue problem. I have a term that looks like $H\psi(x,y) = [-\frac{...
2
votes
1answer
151 views

Optimize custom probability distribution in Python [closed]

Consider random variables $X$ and $Y$, their distributions are given. $Z = f_a(X, Y)$ where $f(\cdot, \cdot)$ is a deterministic, not random function $f_a: \mathbb{R}^2 \to \mathbb{R}$ depending on a ...
2
votes
0answers
192 views

How to reuse permutation-orderings within scipy's SuperLU-wrapper?

i'm solving sparse linear equations within scipy 0.18 which internally resorts to SuperLU (after umfpack got removed due to license-issues). Current, i'm doing a complete re-factorization in each ...
7
votes
3answers
1k views

How do I reliably generate random numbers in Python distributed across multiple nodes?

Consider the following scenario: I want to perform a large Monte Carlo simulation across a compute cluster with several nodes. To avoid excessive transmission of data, I am going to generate random ...
2
votes
1answer
938 views

Applying the result of Cuthill-McKee in SciPy

I have applied SciPy's implementation of the Cuthill-McKee algorithm to a $48 \times 48$ sparse non-symmetric matrix in Compressed Sparse Row (CSR) format and the output is an array of length $48$ ...
1
vote
0answers
95 views

Numerical method to find stationary solution of an PDE in the phase space

I'm relatively new in numerical methods for PDEs, so I have a question about solving the following PDE numerically for $W(x,p)$ in the phase space: $$-p\frac{dW}{dx}+x\frac{dW}{dp}+\frac{d}{dx}\left(...
1
vote
1answer
239 views

3-dimensional plotting with nonuniform grids

I have 3 variables I am considering: time (t), 1-dimensional space (x), and intensity (I). I would like to plot the intensity in the z-axis as a function of t and x (the latter two variables would ...
2
votes
1answer
2k views

Contour plot interpolation recommendation

I am not sure if my question is on topic or not and if not please let me know. I have regularly spaced gridded data(output of a weather forecast simulation software) and I have latitude and ...
3
votes
2answers
434 views

Python environments for AMG and Gauss Seidel as solvers instead of preconditioners

I am working on block preconditioning and seemingly it is common to write customised Krylov solvers for them. Within each solver, the individual block linear system with preconditioners are ...
1
vote
1answer
97 views

Vectorizing list of different functions for Gradient Descent

I am new to machine learning and statistical analysis and am having trouble figuring how I should go about a problem I have. I believe that I understand the gradient descent algorithm and how it ...
1
vote
0answers
51 views

Computing 3-term Connection Coefficients for Wavelets

I am trying to calculate the three-term connection coefficients $$ Λ_{l,m}^{d_1,d_2,d_3} = ∫_{-∞}^∞ φ^{(d_1)}(x) φ^{(d_2)}_l(x) φ^{(d_3)}_m(x) dx $$ for Daubechies wavelets numerically using Python. ...
0
votes
1answer
177 views

Meaning of this minimal python and FEniCS based wave propagation code? [closed]

This is a question about understanding a piece of random code that does not necessarily require knowledge of it's theory. This is very specific and may not be of use to the community in general but ...
0
votes
2answers
452 views

Help implementing finite difference scheme for heat equation

I am trying to solve the following problem via a finite difference approximation: $u_t = k \, u_{xx}$, on $0 < x < L$ and $t > 0$; $u(0,t) = u(L,t) = 0$; $u(x,0) = f(x)$. I take $u(x,0) = ...
3
votes
2answers
486 views

Zero Eigenvalues in Lanczos Algorithm

I need to find the smallest few eigenvalues of a Hamiltonian (exact diagonalization) I use Python, and SciPy's built-in sparse eigenvalue solver. I notice, however, that for my small system (only a ...
1
vote
0answers
155 views

Python DFT library using MPI

I am looking for a discrete Fourier transform (DFT) library that can be run with MPI on Python. Usually, in other language (C, fortran) FFTW is used. There's a Python wrapper for FFTW called pyFFTW, ...
8
votes
3answers
3k views

What does Python offer for distributed/parallel/GPU computing?

Using the SciPy/NumPy libraries, Python is a pretty cool and performing platform for scientific computing. I just wonder: When I have to go parallel (multi-thread, multi-core, multi-node, gpu), what ...
3
votes
0answers
905 views

Efficiently creating an adjacency matrix from a lattice in numpy

I have an $n$ by $m$ numpy array representing a rectangular lattice $L$, where each site contains a one or a zero, representing two different materials. I'm modelling heat flow across this lattice. ...
3
votes
3answers
456 views

State of the art in parallel data structures [closed]

I'm currently evaluating how I could implement several algorithms on a parallel computer with a large number of nodes, each also equipped with a powerful GPU. It turns out that for many algorithms, it ...
1
vote
1answer
361 views

Preconditioning of two step iteration for dense matrices

I would like to solve a dense linear system the form in python $$ L\left(\boldsymbol{x}\right):=\left[\gamma^+\left[\boldsymbol{A}+\frac{1}{2}\boldsymbol{B}^{-1}\right] +\gamma^-\left[\boldsymbol{A}-\...
5
votes
1answer
2k views

Solve rate equations with different reaction orders using SciPy ode

The image below illustrates the kinetic scheme I am trying to model. My first example focuses on the conversion of the wood-oil to non-volatiles and volatiles. The rate equations are as follows: $$ ...
2
votes
0answers
119 views

Clustering similar words and mapping to numbers in Python

I'm familiar with kmeans to cluster data points, but not text.. So I have one column of words in cvs format, which I want to cluster those which have similar word or more, and then mapping those ...
0
votes
1answer
740 views

Solving coupled differential equations with multiple independent variables

I am currently using the wrapper odeintw for scipy.integrate.odeint to solve my equations since they are complex-valued. At the moment, I have 3 coupled first-order differential equations with 2 ...
1
vote
0answers
165 views

Generalized Hermite Function as eigenfunction of a differential operator

I'm going through this paper. The article defines function function $\phi_n^\mu(x)$ that is orthonormal on $L^2$ with measure $dm = dx$: \begin{equation} \phi^\mu_n =\left(\frac{\gamma_\mu(n)}{\...
3
votes
1answer
1k views

Why am I not seeing faster neural network training after upgrading to a vastly better GPU?

I was previously running my neural networks using the Lasagne library to build and train neural networks in Theano on an NVIDIA GTX 750 Ti. I'm using a genetic algorithm to tune the hyperparameters of ...