NumPy is the fundamental package for scientific computing with Python.

learn more… | top users | synonyms

2
votes
1answer
65 views

High frequency noise at solving diffusion equation

I'm trying to simulate a simple diffusion based on Fick's 2nd law. ...
3
votes
1answer
63 views

spectral decomposition in Numpy, sign difference

I am trying to follow along with an example from a book, but I get seemingly different answers depending on which spectral decomposition function I use in Numpy. I am trying to transform the Matrix G, ...
1
vote
3answers
109 views

Can numpy.linalg.solve use back substitution when possible?

The question is if Python Numpy library can use back subsitution to solve Ax=b if possible, that is, if A is lower triangular? Do numerical linear algebra packages do this? I would think Numpy would ...
1
vote
1answer
42 views

detecting special $2 \times 2$ matrices in a large array of zeros and ones

I have a large array of zeros and ones and I need to count instances of 0 1 1 0 0 0 1 1 0 1, 1 0, 1 1, 0 0 And I would like to exclude all ...
2
votes
1answer
80 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} ...
1
vote
2answers
104 views

evaluating a function along an axis in numpy

I have a numpy function f that takes arrays as arguments and a 3D array x[a,b,c]. I would ...
5
votes
1answer
130 views

Finite Volume Implementation

I am trying to implement a simple finite volume method solver. I had a class on FVM a while back, but am still aware of the principal concepts. But implementing the FVM for non-cartesian or 1D meshes ...
0
votes
1answer
109 views

Successive over-relaxation not converging (when not done in-place)

I'm trying to find the potential given some boundary conditions using the successive over-relaxation method. I have 2 solutions: -One iterates over all elements and applies the formula ...
2
votes
3answers
151 views

Caculating the mean of vector accurately

I am having trouble with calculating a mean of vector with sufficient accuracy. My current solution which works but it quite slow and has unpredictable performance: mean_sum = mean = ...
1
vote
1answer
125 views

Using multiprocessing to assign values to a numpy array [closed]

I have a code similar to this: ...
8
votes
2answers
165 views

Continuity of eigenvectors of parametric matrix

I have $n$-dimensional matrices $\mathrm{\hat{H}}(\vec{k})$ depending on vector parameter $\vec{k}$. Now, eigenvalue routines return eigenvalues in no particular order (they are usually sorted), but ...
4
votes
1answer
368 views

Analytic solution 2D scalar wave equation in cylindrical coordinates numerical implementation

I am trying to compare my finite difference's solution of the scalar (or simple acoustic) wave equation with an analytic solution. For that purpose I am using the following analytic solution ...
9
votes
4answers
385 views

Memory efficient implementations of partial Singular Value Decompositions (SVD)

For model reduction, I want to compute the left singular vectors associated to the - say 20 - largest singular values of a matrix $A \in \mathbb R^{N,k}$, where $N\approx 10^6$ and $k\approx 10^3$. ...
0
votes
0answers
40 views

Calculating a confidence value for a posterior statistic

It may be that I'm using "confidence" here in a technically invalid sense, but please bear with me, and feel free to correct my terminology with something more acceptable. I have prior distribution ...
5
votes
1answer
120 views

Calculate large and small frequency separation for the Sun

I want to determine the big and small frequency seperation from timeseries data for the sun. An excerpt of the data (timeseries and power series) is plotted below. The power series is calculated in ...
2
votes
1answer
142 views

Explicit 4th order space wave equation not stable implementation?

The explicit 4th order discretization for the 2D scalar wave equation is given by: \begin{eqnarray} U_{jk}^{n+1} = \left( \frac{\Delta t V_{jk} }{\Delta s} \right) ^2 \left( \sum_{a=-N}^N w_a ...
9
votes
1answer
393 views

Why does SciPy eigsh() produce erroneous eigenvalues in case of harmonic oscillator?

I'm developing some larger code to perform eigenvalue computations of huge sparse matrices, in the context of computational physics. I test my routines against the simple harmonic oscillator in one ...
2
votes
1answer
88 views

python numpy print array(x,y,z) as (x by y) by z?

Printing photo matrices (x,y,z) where z is 0:2 colour, I want to see (x in rows, y in columns) 3 times, once for each colour (the way I've been taught by every mathematician). By default, numpy does ...
21
votes
1answer
458 views

How does the performance of Python/Numpy array operations scale with increasing array dimensions?

How do Python/Numpy arrays scale with increasing array dimensions? This is based on some behaviour I noticed while benchmarking Python code for this question: How to express this complicated ...
13
votes
2answers
394 views

How to express this complicated expression using numpy slices

I wish to implement the following expression in Python: $$ x_i = \sum_{j=1}^{i-1}k_{i-j,j}a_{i-j}a_j, $$ where $x$ and $y$ are numpy arrays of size $n$, and $k$ is a numpy array of size $n\times n$. ...
9
votes
1answer
362 views

Numerical integration for modelling curve for superconductors (Python)

I am a physicist who is trying to model the current-voltage characteristics of a superconductor-superconductor junction. The equation for this model is: \begin{align} I(V) = ...
3
votes
2answers
394 views

vectorizing a non-trivial function in numpy

I have a 2d numpy array, with shape (100,3) a = np.random((100,3)) and I want to call a function ...
3
votes
2answers
564 views

Consistent handling of division by zero in numpy array

I want to populate a numpy array with values from the smooth bump function f(x) = exp ( - 1 / (1 - x^2) ) if |x| < 1, f(x) = 0 otherwise Currently I ...
3
votes
1answer
780 views

Logistic regression with Python

I am trying to code up logistic regression in Python using the SciPy fmin_bfgs function, but am running into some issues. I wrote functions for the logistic ...
2
votes
1answer
135 views

Reshape and Index (State) Products in Numpy

Consider the following: I start with a $2\times 2$ matrix $W_{ij}$. I then take this $W$ matrix and make a new tensor, $T$, by doing the following: $$ T_{ijkl}=\sum_{a}W_{ai}W_{aj}W_{ak}W_{al} $$ ...
16
votes
5answers
2k views

Quickly permute a large square matrix in python 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 ...
1
vote
1answer
315 views

f2py: error f90 not supported by GnuFCompiler needed for source_file.f90

I'm trying to install a Python package that relies on extensions built from Fortran 90 using f2py, but I get the following error: ...
3
votes
1answer
253 views

32bit/64bit issue when working with Numpy and petsc4py

When indexing PETSc.Mat A with an array c ( numpy.ndarray with ...
4
votes
1answer
410 views

Python syntax for MATLAB/Octave colon operator a:dx:b

I am trying to rewrite some MATLAB/Octave code in Python, and I don't know what would be the nicest or most intuitive way of writing ...