# Questions tagged [numpy]

NumPy is the fundamental package for scientific computing with Python.

34 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
372 views

### fastest way to compute many small dot products

I have two n-by-3 blocks contiguous in memory ("n vectors of length 3") and I'd like to compute the dot product between each of the rows as fast as possible. In numpy, using ...
98 views

### How to troubleshoot numerical instability using finite difference for steady-state non-linear heat conduction equation

I have a problem which I believe is numerical instability when trying to solve a heat conduction equation using finite difference. The short version is that when the parameter $I=80.3$ I get the blue ...
1k views

### Python - calculation time derivative and laplacien by finite differences

I would like to determine a temporal derivative 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 ...
159 views

### How amenable is this 2D Frenkel–Kontorova-like energy minimization problem in Python to the use of a modest PC + GPU? (Heavy reliance on indexing)

@Richard's answer to Going to try to move some of my scipy/numpy calculation to a new GPU, how to avoid disappointing results? is quite helpful, and as promised I've added a simple running example ...
137 views

### Solving multiple linear regression in parallel

I am working on a problem where I need to solve approximately 500 Million Linear Regressions (OLS). What would be the most efficient way to do this (e.g. using GPU or a some framework that can do this ...
124 views

### Difference between wave vector and density matrix in numerical calculation of Schrödinger equation

I solved Schrödinger equation for a following tow-level time-dependent Hamiltonian numerically in two ways: ...
100 views

### Inconsistency in optimize.minimize

I am trying to fit a time-dependent curve at each time step. I do so in minimizing along $x_c$ the quadratic error between the curve and a reference solution $1/(1 + \exp\left(\sqrt{S}(x-x_c)\right)$...
209 views

### Optimizing for loops by using Einstein summations instead

I have some Python code containing a couple of for loops, which I would like to optimize by using low-level functions. My first approach is to use ...
2k 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. ...
321 views

### matplotlib contourplot for $\log z$ in the Complex Plane $\mathbb{C}$

I tried using Python's matplotlib on the logarithm and here is what I got, a kind of starburst pattern. Since the angle jumps between $\theta = 0$ and $\theta = 2\pi$, contour assumes there is a ...
93 views

### How to save multiplication computation time between a dense vector and a not that sparse matrix?

I am trying to compute $\mathbf{X}\mathbf{u}$ for many times in my algorithm, where $\mathbf{X}\in \mathbb{R}^{n\times m}$ and $\mathbf{u} \in \mathbb{R}^{m}$. The problem is that, during the ...
290 views

### How can I reduce the artifact in "Thin Plate Spline" interpolation?

At the Top "right", there is the 2D-density plot of the recorded data (actual), fewer in number. Recorded data has been sampled a on the 8 arms of a regular octagon. These 8 arms are placed ...
575 views

### What algorithm do BLAS and ATLAS use for matrix multiplication?

I have searched and what I understood was that they use the naive one with several memory and cache optimizations. However, I wanted to know whether they are using the Strassen or the Coppersmith-...
99 views

### Is the numerical resolution of this huge sparse polynomial system tractable?

I'd like to find numerically a solution to a sparse system of 2000000 polynomial equations of degree 3 with 50000 variables and integer coefficients (or at least to decide whether or not a solution ...
1 vote
72 views

### Convolution/weighted average of two arrays in Python

I have an equation that I need to calculate numerically, but I am having doubts about my approach. I am cross-posting this question from Stack Exchange, because I am not getting any responses. This is ...
1 vote
192 views

### Trouble inverting complex matrix with numpy and scipy

I have some matrix-valued, complex data $Z(f)$ with $f\in\{f_0,f_1,\dots\}$ and $Z(f_i)$ being a 3x3 matrix. I require the inverse $Z^{-1}(f)$ in my workflow. After encountering some problems with my ...
1 vote
45 views

### Interpolate location based on triangular sensor array

There are 3 sensors (A, B, C) on a plane, located in the corners of a (known) equilateral triangle. I want to calculate the (2D) location of an object (X) inside that triangle. One sensor returns one ...
1 vote
64 views

### Help with vectorized computation where vector multiplication would need to create an additional dimension

I want to use vectorized computation (with python and numpy) to do some calculation involving bessel functions. As is often the case, I need to calculate the sums of bessel functions of (infinit) ...
1 vote
Good evening, I would like to understand why I do not get the correct result: I assume that I know my function on discrete data points and expand it as a discrete Fourier transform: $\text{sin}(x)=\... 1 vote 0 answers 147 views ### computing dual matrix trace norm and tensor gradient in python I'm trying to write the following function in python: $$f_\mu(\mathcal X) = f_0(\mathcal X) + \sum_{i = 1}^n \max_{||\mathcal Y_{i(i)}|| \leq1} \alpha_i\langle \mathcal X_{(i)},\mathcal Y_{i(i)} \... 1 vote 0 answers 354 views ### Rank filter on an nXm array using python I would like to apply a rank filter on an nXm numpy array. Let's say I have this array: ... 1 vote 0 answers 52 views ### Update model parameter with new data, discarding old data I have this dataset, and I am using y = (a * x^n) / (b + x^n) Hill function as the model, where a is the limit of the Hill curve,... 1 vote 0 answers 2k 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 ... 1 vote 0 answers 294 views ### Inverse quadratic method only makes one iteration - python I'm tryin' to implement this method with python3 but i don't solve the problem. This is my code: ... 1 vote 0 answers 1k 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 ... 0 votes 0 answers 72 views ### About Convolution Theorem ... 0 votes 0 answers 55 views ### Eigenvalues of same operator expressed in two different orthonormal basis are coming out different I have an operator H. I express H as a matrix in the orthonormalized \{ |e > \} basis. Then I diagonalize it to obtain eigenvalues, let's say for example H is 6 \times 6 and the ... 0 votes 0 answers 83 views ### Advance a Interpolation Note; No special knowledge of Pykrige is needed to answer the question, as I already mention examples in the question! Hi I would like to use Universal Kriging in my code. For this I have data that ... 0 votes 0 answers 103 views ### Plotting the motion of a positive charge in a cylindrically symmetric magnetic field I want to plot the motion of a positive charge in a cylindrically symmetric magnetic field. I am assuming a cylinder around the z-axis, with the magnetic field going in clockwise direction. The B-... 0 votes 0 answers 141 views ### Getting euclidean distance between vector A and C without anyway of retrieving them when their distances with a common vector B is known Motivation: My plan is to get the overall euclidean distance matrix for all the vectors in N number of dataset. Each dataset is basically an array of n-dimensional points. For e.g: A dataset can be ... 0 votes 0 answers 477 views ### How to take convolution of two arrays in Python by using NumPy? Generally, we know that if we have this relation between Fourier transforms of three functions in frequency domain as:$$\mathfrak{F}\{\mathsf{P}(t)\} = \mathfrak{F}\{\mathsf{Z}(t)\}\mathfrak{F}\{\... 0 votes 0 answers 158 views ### Smoothing FFT result I am trying to calculate the spectrum of Bremmstrahlung, which involves calculating the Fourier transformed acceleration. I am solving a non-linear ODE to numerically calculate the acceleration in the ... 0 votes 1 answer 194 views ### Specifying mesh spacing for DFT in numpy I was testing the .fft package of numpy 1.16.1 in Python 3.7.2. In particular I was trying to verify that the transform resembles the analytical one for:$\$f(x) = \mathrm{exp}\left[-\left(\frac{x-5}{2}... 