Stack Exchange Network

Stack Exchange network consists of 174 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.

8
votes
3answers
3k views

fmincg implementation in Python

I'm trying to re-implement Neural Networks in Python. I implemented the cost function and the backpropagation algorithm correctly. I have checked them by executing its Octave equivalent code. But ...
4
votes
1answer
3k views

Using scipy.optimize to implement a neural network with back propagation

My problem is something similar to this. I'm trying to implement a (Neural Network) Cost function, Back propogation algorithm in Python. The Neural Network has 3 layers. Hence 2 parameters to ...
0
votes
0answers
359 views

How to move particles in a variational Monte Carlo simulation?

I'm attempting to implement some code that moves particles and then calculated the acceptance/rejection of the move, but I'm stuck in a rut. Here is my Python code: ...
11
votes
2answers
6k views

CVXOPT VS. OpenOpt

CVXOPT: http://abel.ee.ucla.edu/cvxopt/index.html OpenOpt: http://openopt.org/Welcome What's the relation between them? What are the advantages/disadvantages of them, respectively? BTW, is there any ...
24
votes
5answers
13k views

Permute a matrix in-place in numpy

I want to modify a dense square transition matrix in-place by changing the order of several of its rows and columns, using python's numpy library. Mathematically this corresponds to pre-multiplying ...
8
votes
3answers
3k views

random number generation from cython

I want to make my python program fast by using cython, but my inner loop is still making slow python calls to the random number generator! Several years ago this same issue was raised by someone on ...
6
votes
3answers
758 views

What is the best way to get erfi with scipy?

I want this: http://mathworld.wolfram.com/Erfi.html But apparently scipy does not have this in its extensive special functions library. http://docs.scipy.org/doc/scipy/reference/special.html It is ...
5
votes
3answers
3k views

Storing a large, sparse array for R and Python

I've been working in R but sometimes switching to python. I'd like a more inter-language portable way of storing a large array than a csv file. (The particular csv file I'm dealing with is about 10^6 ...
31
votes
3answers
96k views

What is the simplest way to do a user-local install of a python package?

I don't want to deal with virtualenv for a local Python installation, I just want to install a few packages locally without dealing with the PYTHONPATH environment ...
11
votes
2answers
4k views

Guides on Python for shared-memory Parallel Programming

I have experience in coding OpenMP for Shared Memory machines (in both C and FORTRAN) to carry out simple tasks like matrix addition, multiplication etc. (Just to see how it competes with LAPACK). I ...
11
votes
2answers
4k views

Solving a least squares problem with linear constraints in Python

I need to solve \begin{alignat}{1} & \min_{x}\|Ax - b\|^2_{2}, \\ \mathrm{s.t.} & \quad\sum_{i}x_{i} = 1, \\ & \quad x_{i} \geq 0, \quad \forall{i}. \end{alignat} I think it is a ...
6
votes
2answers
2k views

Updatable SVD implementation in Python, C, or Fortran?

I would like to do evolving factor analysis using the SVD: Given $m \times n$ data matrix $\mathcal{A}$, and for each $i$ from 1 to $m$, I want to calculate the singular values of: $$\mathcal{A}\...
7
votes
5answers
8k views

Interpolate 2D data

I generated a cartesian grid in Python using NumPy's linspace and meshgrid, and I obtained some data over this 2D grid from an ...
7
votes
3answers
771 views

How to handle large numbers of output data sets from a simulation/sensitivity analysis?

Somewhat related, but I think the question is distinct enough to justify a separate question. As a bit of background, I come from a observational/statistical Epidemiology background, working with ...
29
votes
4answers
2k views

What tools or approaches are available to speed up code written in Python?

Background: I think I might want to port some code that calculates matrix exponential-vector products using a Krylov subspace method from MATLAB to Python. (Specifically, Jitse Niesen's expmvp ...
18
votes
5answers
2k views

Parallel Scientific Computation Software Development Language?

I want to develop a parallel scientific computation software from scratch. I want some thoughts on which language to start. The program involves reading/writing data to txt files and doing heavy ...
11
votes
1answer
4k views

Algorithms for community detection for bipartite graphs?

Are there any algorithms for community detection for bipartite graphs (2-mode networks) implemented in igraph, networkX, R or Python etc.? In particular, is there such an implementation in which one ...
0
votes
1answer
1k views

1d shock tube problem, and the solution [closed]

I have solved 1d shock tube problem. (Euler's equations). Using following steps: 1) Define Riemann problem over the domain 2) Carry out local linearisation 3) Based on linearisation, write eigen ...
15
votes
2answers
1k views

(how to) write simulations that run faster?

I have started using python as the programming language for doing all my assignments in CFD. I have a very little experience in programming. I am from mechanical engineering background and am pursuing ...
8
votes
2answers
5k views

Solving non-linear singular ODE with SciPy odeint / ODEPACK

I want to solve the Lane-Emden isothermal equation [PDF, eq. 15.2.9] $$\frac{d^2 \!\psi}{d \xi^2} + \frac{2}{\xi} \frac{d \psi}{d \xi} = e^{-\psi}$$ with the initial conditions $$\psi(\xi = 0) = 0 \...
25
votes
8answers
5k views

Which package should I use to wrap Modern Fortran Code with Python?

I know of, and have used f2py2e to wrap some old Fortran 77 code, but my understanding is that it does not work with newer Fortran 95 code. I've researched what I should use, and have come across ...
20
votes
3answers
10k views

Recommendation for Finite Difference Method in Scientific Python

For a project I am working on (in hyperbolic PDEs) I would like to get some rough handle on the behavior by looking at some numerics. I am, however, not a very good programmer. Can you recommend ...
28
votes
9answers
1k views

What is a good way to run parameter studies in C++

The problem I'm currently working on a Finite Element Navier Stokes simulation and I would like to investigate the effects of a variety of parameters. Some parameters are specified in an input file ...
11
votes
2answers
2k views

Efficiency of using petsc4py vs. c/c++/fortran

How much slower is petsc4py vs c/c++/fortran? I realize it will depend significantly on the code being executed, but what about something simple like a matrix-vector product?
11
votes
4answers
1k views

Making a Molecular editor/visualizer: Object oriented programming, data structures, and molecules

I am new to programming and I am trying to solve my first big problem and write my first big program. I have looked for open source examples of code to learn from, but so far have only found code in ...
6
votes
1answer
12k views

scipy.optimize.fmin_bfgs: “Desired error not necessarily achieved due to precision loss”

I am getting the warning in the post subject when attempting to optimize a function in Python with the scipy.optimize.fmin_bfgs function. The complete output: Warning: Desired error not necessarily ...
11
votes
4answers
4k views

What are the best Python packages/interfaces to sparse direct solvers?

Please list the Python package (petsc4py, etc...) and the sparse direct solvers it supports. One (community-wiki) answer per package, please.
3
votes
0answers
152 views

Is there an easy way to read a PetscBag into a python dict?

I'm using a PetscBag to store the input parameters of my program. At some point, I'm going to need to use python to plot these parameters against some output parameters, and ...
15
votes
3answers
2k views

I/O Strategies for computational problems with large data sets?

My research group focuses on molecular dynamics, which obviously can generate gigabytes of data as part of a single trajectory which must then be analyzed. Several of the problems we're concerned ...
3
votes
0answers
66 views

Understanding how Numpy does SVD [duplicate]

Possible Duplicate: Understanding how Numpy does SVD I have been using different methods to calculate both the rank of a matrix and the solution of a matrix system of equations. I came across the ...
13
votes
3answers
7k views

Understanding how Numpy does SVD

I have been using different methods to calculate both the rank of a matrix and the solution of a matrix system of equations. I came across the function linalg.svd. Comparing this to my own effort of ...
5
votes
1answer
1k views

Drawing isocontour data of 3d discrete volume with mayavi2

I'm trying to visualize the propagation of heat in a discrete sphere surface. The sphere is hollow, only the voxels of the boundary have value. Visualization in matlab using isosurface shows correct ...
11
votes
4answers
6k views

solving coupled ODEs with initial-value and final-value constraints

The essence of my question is the following: I have a system of two ODEs. One has an initial-value constraint and the other has a final-value constraint. This can be thought of as a single system with ...
18
votes
2answers
13k views

Define custom probability density function in Python

Is there a way, using some established Python package (e.g. SciPy) to define my own probability density function (without any prior data, just $f(x) = a x + b$), so I can then make calculations with ...
30
votes
8answers
2k views

Scientific workflow management system

Can anyone recommend me a good workflow management system (WMS), preferably in Python? So far I have been using GNU Make, but it introduces a layer of complexity that I want to avoid. A good WMS ...
3
votes
1answer
840 views

Solve log equations problem [SageMath]

Input var('x') solve((log((x**2 - x), 6) - log((6*x - 10), 6) == 0), x) Output [log(x^2 - x) == log(6*x - 10)] But real ...
8
votes
4answers
3k views

High Order derivatives of splines using SciPy

I have created a spline to fit my data in python using: spline=scipy.interpolate.UnivariateSpline(energy, fpp, k=4) The equation I want to use involves a ...
5
votes
5answers
10k views

How can I plot piece-wise defined function in some easily-accessed open-source tool?

I want to plot $$f_{n}(x) = \begin{cases} x-n & \text{for } n \leq x \leq n+1 \\ 2-x+n & \text{for } n+1\leq x \leq n+2 \\ 0 &...
11
votes
4answers
457 views

Runge-Kutta and Reusing Datapoints

I am trying to implement the fourth order Runge-Kutta method for solving a first order ODE in Python i.e. $\frac{dy}{dx} = f(x,y)$. I understand how the method works, but am trying to write an ...
6
votes
2answers
373 views

Filtering a dataset to get a more uniform distribution for neural network training

I'm looking into using artificial neural networks (ANN) to predict the reaction rates in my fluid instead of solving the full system of stiff ODEs. Some people from my lab have already done some work ...
1
vote
0answers
80 views

Constraint solving over modular domains

I have a set of constraints over modular domains e.g. $\exists a \in A_i : x \equiv a \pmod{n_i}$ for all $i=0,\ldots,k$ The question is, does such an $x$ exist? I've been pointed to method of ...
5
votes
1answer
1k views

creating a flat surface in python

I'm trying to create a figure of particle distribution from a reference surface in python. I plan to get a distribution in python and then prettify it with tikz. I tried this: ...
7
votes
6answers
5k views

Python implementations of Gillespie's direct method

I'm looking for a decent implementation of Gillespie's Direct Method in Python, as if I code the algorithm myself I'm nigh positive I'll do it inefficiently. Anyone have a favorite?
72
votes
17answers
78k views

Is there a high quality nonlinear programming solver for Python?

I have several challenging non-convex global optimization problems to solve. Currently I use MATLAB's Optimization Toolbox (specifically, fmincon() with algorithm=<...