Skip to main content

Questions tagged [numpy]

NumPy is the fundamental package for scientific computing with Python.

Filter by
Sorted by
Tagged with
1 vote
1 answer
82 views

Consider the regularized logistic regression problem: $$\min_{\theta \in \mathbb{R}^n}\sum_{i=1}^m \ln \left(1+e^{-y_i\theta^T x_i}\right)+\frac{\lambda}{2}\big\lVert\theta\big\rVert^2_2.$$ Here, $y_i ...
Sid Meka's user avatar
2 votes
1 answer
156 views

I have learnt scientific computing back in the time when C and C++ were the thing, and I'm relatively new to ...
Joce's user avatar
  • 384
1 vote
1 answer
245 views

Let’s suppose we are working in a discrete setting with fixed intervals and want to compute the area under a known continuous function without taking the limit as Δx → 0. Example: Consider the ...
Veni's user avatar
  • 13
4 votes
1 answer
249 views

We all learned in Calc 1 how to take derivatives of polynomials. What we were probably not told, is that this is but one possible expression of a function, in terms of a "power series", and ...
Pavel Komarov's user avatar
1 vote
0 answers
44 views

I have two time series X and Y of length ~2 million. I have a parameter window_size which is ...
kaddy's user avatar
  • 11
1 vote
0 answers
115 views

So, we have to calculate eigenvalues and eigenfunctions for this one assignment. In short, we are using a Quantum Harmonic Oscillator. If you want to read the full thing , Here: The probability ...
Sid Meka's user avatar
0 votes
0 answers
138 views

I should write a Rayleigh quotient iteration function x, k = rayleigh iterate(A,x0, eig), which takes a matrix A, an initial vector x0, and an approximate eigenvalue eig as arguments and returns an ...
user50873's user avatar
4 votes
1 answer
2k views

I’m writing some Python code using NumPy. Since I got an overflow warning, I decided to check for underflows as well at all places in the code, using ...
NNN's user avatar
  • 908
4 votes
1 answer
153 views

Given a special orthogonal matrix $O$ (i.e: $OO^T = 1$ and $\det(O) = 1$), I am trying to efficiently find a matrix $X$ such that $O = e^X$ and $X = -X^T$ using Python (NumPy & SciPy). One obvious ...
Solarflare0's user avatar
1 vote
0 answers
68 views

I have the following expression that I need to calculate for some matrices: $$ \sum_{k}c_{t,i,k}\sigma^\prime\left(w_tX_t+b_t\right)_k\left(\sum_\ell w_{t,k,\ell}\tilde{X}_t^{w,\ell}\right) $$ I could,...
Gummy bears's user avatar
0 votes
0 answers
112 views

I wanted to understand how the fast fourier transform work in numpy and for this I tried apply it on $n$ points of an ellipse $t_k = \frac{2\pi}{n-1}k$ with $k=1...n$ $$f_k = f(t_k) = (acos(t_k), bsin(...
edamondo's user avatar
  • 225
0 votes
1 answer
341 views

I'm trying to do something that I thought would be very straightforward but somehow I'm struggling. I have a time series and I want to extrapolate it, assuming a linear trend, to forecast when will it ...
user avatar
12 votes
1 answer
425 views

I noticed that libraries like numpy and pytorch are able to perform arbitrary tensor contractions at speeds similar to comparably sized matrix multiplications. This leads me to believe that underneath ...
ilya's user avatar
  • 131
5 votes
2 answers
2k views

I am solving differential equations that require inverting dense square matrices, and I wanted to know what algorithm(s) do numpy and scipy use to calculate matrix inverses?
kamy rez's user avatar
1 vote
1 answer
179 views

I have a Python program (available on github) that uses naive gradient descent to find approximate solutions to the Thomson Problem. It works surprisingly well, but I've been wondering if there's a ...
Martin C.'s user avatar
  • 229
3 votes
0 answers
360 views

I have a 3D vector field and I want to extract its divergence-free part (also called transverse component), using the Helmholtz decomposition. In principle, this can be done in the Fourier space, as ...
Wil's user avatar
  • 31
1 vote
1 answer
1k views

Suppose the metric is abs(a-b) <= rtol * max(abs(a), abs(b)) i.e. math.isclose with ...
OverLordGoldDragon's user avatar
0 votes
1 answer
99 views

I need to compute a series of matrix multiplications involving 3x3 matrices and a series of matrix norms also involving 3x3 matrices and I wonder how I can set these computations up with numpy such ...
Mantabit's user avatar
  • 121
0 votes
0 answers
125 views

...
Deepak Kallepalli's user avatar
3 votes
1 answer
2k views

Can someone give an estimate of the Time and memory required to diagonalize a 20000 by 20000 complex hermitian matrix using numpy in python ?
Snpr_Physics's user avatar
1 vote
0 answers
163 views

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 ...
theWrongAlice's user avatar
0 votes
0 answers
69 views

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 ...
Snpr_Physics's user avatar
2 votes
1 answer
1k views

I have two values $a$ and $b$ where $a \ge 0$ and $b \ge 0$ and I have to calculate the formula below. $$ \frac{1}{2}\int_0^1\text{abs}\left[\left( \frac{p_i^{(a - 1)} \times (1 - p_i)^{(b - 1)}}{\...
Bhavana Reddy's user avatar
0 votes
1 answer
492 views

Given a list of points that were randomly generated around two lines, find two new lines that match the original lines as closely as possible. Here's the function definition: ...
user143758's user avatar
0 votes
1 answer
141 views

CSV (even though once opened it does not contain a traditional CSV format I think it contains JSON data)[![1], when I try to open it as a TXT file I got this as shown in the first screenshot. When I ...
Diorageek's user avatar
0 votes
1 answer
165 views

This is not a homework, but a hobby project, and maybe not all terms I use are correct - please help to fix. Imagine there are K vectors in n-dimensional space. I would like to: validate whether they ...
Open Food Broker's user avatar
2 votes
0 answers
149 views

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 ...
Xun Maoapo's user avatar
0 votes
0 answers
115 views

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 ...
Weiss's user avatar
  • 1
3 votes
0 answers
562 views

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 ...
Subhadip Saha's user avatar
-1 votes
1 answer
236 views

I want to fit this data. I have the following model functions. Classic gaussian: def gauss_model(x, mu, sigma): return np.exp(-0.5*((x-mu)/sigma)**2) And ...
trynerror's user avatar
1 vote
1 answer
114 views

My Math SE question determining if a coincident point in a pair of rotated hexagonal lattices is closest to the origin? explains the problem I have. I won't reproduce the whole thing in detail here, ...
uhoh's user avatar
  • 1,152
5 votes
1 answer
1k views

I want to use the SDEint package to give a numerical solution (plot) of the following stochastic SIR model. Namely, a system of SDEs. $$\begin{cases} dS = -\beta SIdt - \sigma SIdW \\ dI = (\beta SI -...
oliverjones's user avatar
4 votes
0 answers
220 views

@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 ...
uhoh's user avatar
  • 1,152
1 vote
0 answers
599 views

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 ...
totally_lost's user avatar
4 votes
1 answer
829 views

update: I've refactored the question based on helpful advice in the linked meta. I'm a heavy user of Python's NumPy and SciPy (and not much else) and for years I could run anything I need on my laptop....
uhoh's user avatar
  • 1,152
5 votes
0 answers
182 views

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 ...
Ken Grimes's user avatar
2 votes
2 answers
374 views

I have a real square matrix $X$ which I need to perform a Singular Value Decomposition on. Now, performing the operation $$ X = USV^T $$ as $U$ and $V$ are orthogonal, we know that $\det(X)=\pm\det(S)$...
cheetah's user avatar
  • 203
2 votes
1 answer
5k views

I'm trying to use solve_ivp from scipy in Python to solve an IVP. I specified the tspan ...
An Ignorant Wanderer's user avatar
0 votes
2 answers
163 views

Let $M_n(\mathbb{R})$ denote the set of $n\times n$ matrices with real entries. I have an $n\times n$ matrix $X\in M_n(\mathbb{R})$, and I would like to implement the linear operator $[X, \cdot] : M_n(...
Solarflare0's user avatar
0 votes
0 answers
140 views

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-...
August Jelemson's user avatar
0 votes
0 answers
158 views

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 ...
Shihab Ullah's user avatar
5 votes
0 answers
297 views

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 ...
runtime's user avatar
  • 51
-1 votes
1 answer
866 views

My Problem: A positively charged particle (mass = 2 * 10-27 kg) is moving along the x-axis. It is travelling in a homogenous magnetic field such that the field axis in z-direction. The energy of the ...
August Jelemson's user avatar
-2 votes
2 answers
263 views

I have these 3 equations and i want to solve them with numerical methods. so I am using scipy library but I don't know how to solve 3 equations together. R, g, sigma and density are constants. \begin{...
amirsafari78's user avatar
3 votes
1 answer
277 views

Say I have a set of $n \times n$ matrices $A_1, ..., A_m$ as numpy arrays. I'd like to create the block matrix defined below. I'm looking for a clean, elegant, and easy-to-interpret way of doing this ...
Alex L's user avatar
  • 213
3 votes
1 answer
444 views

I am trying to find the top k leading eigenvalues of a NumPy matrix (using python dot product notation) L@L + a*[email protected], where $L$ ...
Alex L's user avatar
  • 213
0 votes
2 answers
132 views

Apologies if this is a trivial question. If that is the case I imagine I would benefit from someone explaining where my understanding is lacking. I am having some trouble interpreting the (putatively ...
Martin C.'s user avatar
  • 229
-1 votes
1 answer
394 views

given the following system: $$\frac{dP}{dt} = \alpha P(1-\frac{P}{K}) - \beta P I$$ $$\frac{dI}{dt} = \beta P I - \rho I$$ how do I solve the system numerically. as when I attempt to solve this is the ...
Gideon Ilung's user avatar
1 vote
1 answer
2k views

Here is the output of Numpy np.fft.ifft([0, 4, 0, 0]) array([ 1.+0.j, 0.+1.j, -1.+0.j, 0.-1.j]) # may vary Here is the output of Matlab ...
FreeMind's user avatar
  • 148
3 votes
0 answers
163 views

I solved Schrödinger equation for a following tow-level time-dependent Hamiltonian numerically in two ways: ...
wayna's user avatar
  • 31