NumPy is the fundamental package for scientific computing with Python.

learn more… | top users | synonyms

3
votes
1answer
68 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
23 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
45 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
0answers
46 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
126 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
53 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 ...
15
votes
0answers
174 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 ...
11
votes
2answers
230 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$. ...
8
votes
1answer
206 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) = ...
2
votes
2answers
124 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
107 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 ...
2
votes
1answer
421 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
87 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} $$ ...
12
votes
3answers
609 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
145 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
152 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
255 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 ...