Tagged Questions

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

learn more… | top users | synonyms

2
votes
0answers
29 views

4th order tensor

I'm new with FEniCS and Python and I'm stuck with this issue: is there a way to write a 4th order tensor in an easy way to implement? I have to compute the following stiffnes tensor: $A_{ijkl}= ...
5
votes
1answer
130 views

Numerical evaluation of an elliptic integral in python

Goal: I need to evaluate numerically an integral of the following form: $$ \int_0^\infty \frac{dx}{(a^2+x)\sqrt{(a^2+x)(b^2+x)(c^2+x)}} $$ where $a,b,c \in \mathbb{R}$ are in the interval ...
4
votes
0answers
130 views

Why does Matlab's integral outperform integrate.quad in Scipy?

I am experiencing some frustration over the way matlab handles numerical integration vs. Scipy. I observe the following differences in my test code below: Matlab's version runs on average 24 times ...
1
vote
1answer
31 views

Matlab equivalent of scipy's 'vode' and 'zvode' ode routines

In python I have used the ode method from scipy.integrate. There I used the vodeintegrator ...
1
vote
1answer
85 views

Solving Advection (Convection) - Diffusion - Reaction Partial Differential Equation in Python

I am looking for library written in Python which will enable me to solve the coupled nonlinear equations which looks like: I need the library which will enable me to couple this solver to other ...
11
votes
1answer
821 views

How to avoid catastrophic cancellation in python function?

I am having trouble implementing a function numerically. It suffers from the fact that at large input values the result is a very large number times a very small number. I am not sure if catastrophic ...
2
votes
2answers
119 views

Why does scipy's odeint function give a non-monotonic solution for a problem whose solution should be monotone?

The solution to the ode below looks like it is monotonically increasing: However on closer inspection we see that it is not: How can I ensure that the numerical solution is monotonically ...
1
vote
1answer
71 views

How to deal with indeterminate function limit?

How do I ensure that my function below is well conditioned as $s$ approaches $\infty$? The problem I get is that for large $s$ the function returns an indeterminate form $\frac{0}{0}$. I would ...
0
votes
0answers
18 views

Laplacian of Gaussian (LOG) for Edge Detection

The LOG is determined by the following function as given in this http://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm. I used Excel and also python to get the LOG kernel. But surprisingly my kernel values ...
0
votes
0answers
114 views

Using scipy.quad to calculate difficult integral

When evaluating the integral below in python using scipy.quad I get the following warning: UserWarning: The maximum number of subdivisions (50) has been achieved. If increasing the limit yields no ...
2
votes
2answers
93 views

How to implement Gauss-Laguerre Quadrature in Python?

To get the hang of Gauss-Laguerre integration I have decided to calculate the following integral numerically, which can be compared to the known analytical solution: \begin{align} \int_0^{\infty} ...
2
votes
1answer
103 views

Is there a Gauss-Laguerre integration routine in Python?

I am reading the book "Numerical Recipes in Fortran 77: The Art of Scientific Computing" (Second Edition) and I came across some methods for numerical integration of 1D functions. More specifically ...
2
votes
2answers
82 views

How to generate a rotated (by 90 degrees) logistic sigmoid function in Python

I created this Python function to generate a sigmoid function where I can modify position and width: ...
3
votes
1answer
82 views

Numerically solve a PDE in Python with a term calculated by coarse-graining

I'm trying to solve a PDE in Python of the form, $\dfrac{\partial c(\mathbf{x}, t)}{\partial t} = \mathrm{D} \nabla^2 c(\mathbf{x}, t) -\gamma \rho(\mathbf{x}, t) c(\mathbf{x}, t)$ where $c$ ...
0
votes
1answer
79 views

How can I use Scipy to fit data generated from a C++ model?

I currently have a functioning and blazing fast model written in C++ and CUDA. However, I'd like to use Scipy.minimize to fit the model to some experimental data. I was hoping it would be easy, but ...
1
vote
1answer
31 views

Speedier alternative to “skimage.morphology._pnpoly import points_inside_poly”?

I am using scikit-image's points_inside_poly function, and in my code I am calling it enough times that it takes up about 50% of ...
0
votes
1answer
63 views

Python: Computation time Issue with mpi4py

I am using in Python mpi4py to process in parallel 20 minimization functions. Each of the 20 worker processes the same algorithm but with different random initial ...
2
votes
1answer
102 views

Unwrap cylinder to plane in Paraview

I want to extract the data from the boundary surface of a cylinder (in a .vtu file) and plot it onto a plane, where the coordinates are theta (rotation angle) and ...
1
vote
2answers
82 views

Maximum function evaluation with NLOPT in Python

I am having an issue with the implementation of NLOPT in Python. My objective is to minimize a somewhat complicated Maximum Likelihood function. My function is called mle and there are 6 parameters ...
4
votes
4answers
81 views

Measurement error library

Is there a python library that would keep track of uncertainty in measured data? i.e. if I put in a figure of a±b is there an easy way to track the propagation of error through calculations.
4
votes
2answers
93 views

Line Integral Convolution (LIC) Requirements

I'm trying to plot some vector fields using LIC technique. More specifically, I'm using the Python solution for this kind of plot. Before applying that approach, I was plotting my vectors as quiver. ...
2
votes
2answers
75 views

Parametric spectrum estimation using aryule: difference between Python and Matlab

I have some code illustrating my problem below. As you can see from the results- Matlab is significantly faster than python. It seems that the function which performs the levinson durbin recursion in ...
0
votes
0answers
47 views

Principal Components Analysis Not Behaving as I Expect it to

I have a bunch of points in $\mathbb{R}^3$ that I would like to translate and rotate so that their center is at the origin and the variance along the $x$ and $y$ axes are maximal (greedy, and in that ...
0
votes
0answers
42 views

Python problem — .fit image resize

I'm using the below python code to resize the image that's of '.fit' file type: ...
2
votes
2answers
73 views

Python: What is a good way to generate a 1D particle field with a gaussian distribution?

If I have N particles how do I assign their x values so that the end result is Gaussian distribution. i.e. particles near the ends are more spread out than particles near the center.
0
votes
1answer
84 views

Tanh-sinh quadrature numerical integration method converging to wrong value

I'm trying to write a Python program to use Tanh-sinh quadrature to compute the value of \begin{equation} \int_{-1}^1 \frac{dx}{\sqrt{1-x^2}} \end{equation} but although the program converges to a ...
0
votes
1answer
93 views

Calculating periodicity of a pseudo random number generator (Middle-square method) [closed]

Below is a Python code that calculates the periodicity of the middle-square method for a given 4 digit-numbers: ...
1
vote
1answer
187 views

Python - calculation time derivative and laplacien by finite differences

I would like to determine a temporal derivitive and a Laplacian by the finite differences method to solve the heat equation in a 1-dimensional case. My aim is to get the sources term that is why I ...
1
vote
1answer
80 views

How can a quadratic positive definite minimization be unbounded [closed]

I am minimising a diagonal quadratic matrix using CPLEX. All off diagonal elements are zero. It has 500 variables and 20 linear constraints plus each variable is constrained to be within 0 and 1 All ...
0
votes
0answers
40 views

F2Py with allocatable and assumed shape arrays as callback arguments

I would like to use f2py to overload some fortran subroutines in my main fortran program by python methods. Some of these subroutines receive an assumed shape array. I have found here how to make ...
0
votes
1answer
29 views

Border Mapping of Scatter plot

I have scatter plot and I want to trace the border of that. for example: Plot: and I wanted it traced: Or at least wanted to know the border points? Also, is it possible to detect if any ...
2
votes
1answer
142 views

Organizing a CFD program written in python

I've spent some time writing a spectral element solver aimed at solving fluid flow problems concerning the motion of self-propelled bodies. I've gotten to the point where the code has grown long ...
4
votes
0answers
94 views

Sparse matrix ordering in Python

I would like to implement custom, domain-specific algorithms for sparse matrix orderings. I am looking for Python packages for ordering sparse matrices. It would be nice to have: The underlying ...
4
votes
1answer
161 views

Python: Multistart optimization using parallel programming

[I previously asked my question on StackOverflow but this site may be more appropriate] In Matlab, I am currently using the MultiStart as an optimization algo in a parallel setup for a computer ...
2
votes
2answers
77 views

Python package for (adaptive) function plotting

Are there any mature Python packages that can plot functions, and possibly use adaptive sampling? I am looking to pass only a function (can be a numerical black box) and a range, and expect a plot as ...
3
votes
3answers
260 views

scipy.sparse: Set row/column in sparse matrix to the identity without changing sparsity

I'm using the SciPy sparse.csr_matrix format for a finite element code. In applying the essential boundary conditions, I'm setting the desired value in the right ...
4
votes
2answers
165 views

Using numpy arrays in Paraview programmable filter

How can I access a field in Paraview's programmable filter as a numpy array? I want to: Import an existing field as a numpy array Create a similar array for output Register it as a new field for ...
3
votes
2answers
115 views

scipy odeint: sum of conservative ode equations does not remain zero as it is being solved — is this normal?

Let us say we have the following equations: dy1/dt = f(y1, t) [1] dy2/dt = g(y2, t) [2] The equations are such that they are "conservative", i.e. the ...
0
votes
1answer
115 views

PyOpenGL/OpenGL Generating Cosmic NBodys

I am working on a Universe Simulator. I'm stuck on creating the dark matters webs of the universe that look like this: http://www.mpa-garching.mpg.de/galform/data_vis/sim3dnew-highres.png I am ...
2
votes
1answer
298 views

Poisson equation with Neumann boundary conditions

I'm trying to solve the Poisson equation with pure Neumann boundary conditions, $$ \nabla^2\phi = \rho \quad in \quad \Omega\\ \mathbf{\nabla}\phi \cdot \mathbf{n} = 0 \quad on \quad \partial \Omega ...
2
votes
0answers
123 views

Polynomial Fitting with Least Squares using Numpy and Scipy

I am trying to fit data to a polynomial using Python - Numpy. The points, with lines sketched above them are as in the picture. I am trying to fit those points to a polynomial of 4. or 5. degree. ...
1
vote
0answers
49 views

learning Gurobi for MIP calculation [closed]

I am a new learner of Unix, python and Gurobi for MIP calculation. I basically finish reading the quick start guide in Gurobi website but still feel that I need more training to use this combination ...
1
vote
1answer
248 views

How do I integrate this function in python?

Essentially this is the problem: $\hat{F}(\omega) = \int_0^{\infty} f(s)e^{-i\omega s}ds$ The function $f$ is in general complex valued. I know this looks like the fourier transform but I don't want ...
1
vote
2answers
119 views

How to get ODE solution at specified time points?

The code below basically illustrates my problem. It is a test code for a pendulum. I solve it using a method suggested on ...
1
vote
3answers
195 views

Scripting for High Performance Computing

I would like links to resources which provide codes for scripting (preferably in python) for high performance computing. I'm looking for sample codes and examples which can, (1) automatically create ...
2
votes
3answers
99 views

importing PARI libraries ( in C++) with Python

I noticed that Python does not have a good datatype for rational numbers, certainly not for algebraic numbers like $\tfrac{1 + \sqrt{2}}{3}$ or the real root of $x^3 - 5x + 7$. They have the ...
1
vote
0answers
79 views

PageRank computation as the left principal eigenvector

I'm following the book here to compute PageRank: http://nlp.stanford.edu/IR-book/html/htmledition/markov-chains-1.html I built the transition matrix P as indicated in the book. Then I computed the ...
1
vote
1answer
151 views

WRL and VRML to Matplotlib/Numpy

I would like to import (or parse ??) a WRL/VRML file format in python in order to work the data with Matplotlib. Is there any way of converting this file format into plottable numpy arrays ? I ...
4
votes
6answers
2k views

Python vs FORTRAN

Which one is better: FORTRAN or Python? And I guess that in both cases you need Gnuplot, am I right? I'm working on a Windows machine at the moment. I'd like to use it to get numerical solutions for ...
5
votes
3answers
205 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 ...