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]

For mathematical questions about Python; questions purely about the language, syntax, or runtime errors are off-topic here and would likely be better received on Stack Overflow.

0
votes
0answers
6 views

FIltering out peaks and valleys in a noisy dataset that has drift and hills

I have a dataset from a weight sensor over 14 hours, whos resitance wheter or not something is on a table, which reads one value every second and stores it in a database. In the end the senosor is ...
2
votes
0answers
9 views

Efficient SQP with more equality constraints than parameters

My question is both a math and (computer) programming one so answers related to either are fine. Problem Setup I have the nonlinear programming problem $$ \begin{aligned} \min \;\; &f(X) \\ \...
0
votes
0answers
3 views

normalizing by using gaussian distribution for negative and positive numbers and feed in Min,Max normalization

I'm dealing in Python with a dataset which has 6 million float numbers belongs to 3 main parameters A, B , C and I map them in 24x20 matrices for each cycle and I plot them 480-values by 480-values. ...
1
vote
2answers
27 views

Generate random graphs with specific mean degree and mean edge weight

I need to generate random undirected graphs with the following characteristics: 24 nodes mean degree ranging between 1 and 23 mean edge weight ranging between 1 and 5 (weights must be integers) I ...
0
votes
0answers
16 views

How to take derivative of log loss function in gradient descent?

I know the gradient descent about $z=wx+b$. But how to implement the derivative values of $w$ and $b$ in Python? I see some example like ...
0
votes
2answers
17 views

Understanding percentile computation

I understand percentile in the context of test scores with many examples (eg. you SAT score falls in the 99th percentile), but I am not sure I understand percentile in the following context and what ...
0
votes
1answer
23 views

How to reduce matrix into row echelon form in Python

I'm working on a linear algebra homework for a data science class. I'm suppose to make this matrix into row echelon form but I'm stuck. Here's the current output I would like to get rid of -0.75, 0....
1
vote
0answers
33 views

Calculating Mahalanobis parameters from x data

Roughly speaking, the Mahalanobis distance $d(x) = \sqrt{(x - \mu)^T * \Sigma^{-1} * (x - \mu)}$ is the distance between a multivariate Gaussian distribution ($\mu$, $\Sigma$) and a point. If the ...
0
votes
1answer
27 views

Finding the appropriate polynomial fit for set of data

Is there a function or library in Python to automatically compute the best polynomial fit for a set of data points? I am not really interested in the ML use case of generalizing to a set of new data, ...
1
vote
0answers
51 views

Is there a way to avoid computing the inverse in the problem $\mathbf{y}=AB^{-1}\mathbf{x}$?

I'm writing some code in Python that has to deal with very large matrices so it is virtually impossible (atleast very sub-optimal) to compute inverses of matrices. In an earlier problem I ran into a ...
1
vote
1answer
75 views

How to code oscillator driven by Gaussian white noise? Edit: How to convert ODE to a system of SDE's?

I have written some python code which was designed to try to solve the following differential equation: $$\ddot{x}+\omega_0^2x=\eta(t),$$ where $\eta(t)$ is the gaussian white noise, with mean 0 and ...
0
votes
0answers
29 views

Question about creating a 3-rank tensor in numpy with python3

I'm trying to create a 3-rank tensor in numpy, with python3.x. I need to create this 3-rank tensor A in a very particular way. If I have 3 matrices, let's say that all of them are some $Y$ matrix (...
1
vote
1answer
43 views

Finding arrays of pixels perpendicular to a derivative

I have a question that I originally posted to Stackoverflow, but got no answers, and was encouraged to re-post here. I am developing a method for “straightening” binary-masks of pictures of carrot ...
2
votes
1answer
35 views

Calculate “areas of control” for arbitrary points

Suppose we define the "area of control" (AOC) for a single point $P_1$ as a circle of radius $r=500$ meters $C_1$. This could, for example, define the "customer base" of a small bodega in a big city. ...
0
votes
0answers
51 views

Python monte carlo value at risk with non normal distribution

What is the right way to implement a monte carlo method on a currency portfolio with non normal distribution? I am using a geometric brownian motion with normal random variables but I would like to ...
2
votes
1answer
60 views

Erdős-Straus-conjecture using polynomials in Python

I am trying to write a code in Python to do the following. We can express the Erdős-Straus-conjecture in function of some polynomials $x(k), y(k), z(k) \in \mathbb{Q}[k]$ such that $\frac4k = \frac{1}...
0
votes
1answer
23 views

How to apply this linear transformation $(x:=2x+1)$ on R-sequence result to generate points in range $[-1,1]$?

I want to used R-sequence proposed by Martin Roberts to generate points in range [-1,1]. In this post, Martin Roberts mentioned that: ... to convert to a range of [-1,1], simply apply the linear ...
0
votes
0answers
29 views

Informations about Fourier Transform for a Python project (sound manipulation)

I have a project in Python with a friend where we want to manipulate music sound, and we'll need Fourier Transforms, so I made research online and wanted to know if I understand correctly the concepts....
0
votes
1answer
52 views

Outer product reformulation of LU decomposition

For my numerical analysis class, I wanted to implement the rather simple, in-place LU decomposition algorithm. I did this the naive way and found my code was very, very slow, because I was doing every ...
0
votes
2answers
166 views

Searching for Goldbug Numbers

A Goldbug Number of order k is an even number 2n for which there exists some k order subset of the prime non-divisors of n $2 < p_1 < p_2 < p_3 < \cdots < p_k < n$ such that $(2n-p_1)...
0
votes
1answer
42 views

st.petersburg paradox in python

I have been trying to do the St.Petersburg paradox( the player wins 2 dollars if tail appears on the first toss, 4 dollars if heads appear on the first toss and tails on the second, 8 dollars if heads ...
0
votes
0answers
18 views

Not getting expected results with FFT

So I made this virtual car that moves at a velocity that is the sum of three different sine waves (whose individual frequencies I know). I constructed this velocity time graph Then I perform a FFT on ...
-1
votes
3answers
32 views

What will be the input based on the output?

A = 1.0 B = 1.0 C = A / (1-(B/100)) This will give an output as 1.01 What will be the output when A and C are only given? A = 1.0; B = ?; C = 1.01; 1.10 = 1.0 / (1-(? / 100)) What is the answer ...
1
vote
2answers
41 views

Generating a random sparse hermitian matrix in Python

I'd like to find a way to generate random sparse hermitian matrices in Python, but don't really know how to do so efficiently. How would I go about doing this? Obviously, there are slow, ugly ways to ...
1
vote
0answers
36 views

Epidemic spacial diffusion problem.. how to draw a graph of differential system of second order with partial derivative

I'm currently working on how to simulate the diffusion of an epidemic in a population. If we don't consider that the population is moving in space, then the differential system is the following: ...
0
votes
0answers
12 views

Graphing Quiver and Nullclines on the same graph

I'm new to matplotlib and having some trouble to plot 2-3 functions on a single plot. I tried to find examples but I couldn't find something clear with a nice syntax. I'm wondering how I can plot ...
0
votes
0answers
69 views

Applying neumann boundary conditions to diffusion equation solution in python

For the diffusion equation $$\frac{\partial u(x,t)}{\partial t}=D\frac{\partial^2 u(x,t)}{\partial x^2}+Cu(x,t)$$ with the boundary conditions $u(−\frac{L}{2},t)=u(\frac{L}{2},t)=0$ I've programmed ...
0
votes
1answer
76 views

parabola equation from two points and vertex

For a optimisation task I'm facing a problem that my limited geometrical knowledge can't solve. I have a cloud of points in a 2d plane, where I want to perform some binary metric on to select a ...
3
votes
1answer
70 views

Euler-Lagrange formalism with SymPy

I am trying to use SymPy to apply the Euler-Lagrange formalism to the following Lagrangian function: $$\mathcal{L}(x, \dot{x}) = \mathcal{K}(x, \dot{x}) - \mathcal{P}(x) = \dfrac{1}{2} \mathfrak{m} \...
0
votes
0answers
9 views

Finding a proper way to correlate categorical data when chi_square p value is zero

To summarize the situation: imagine I have two groups of people – each group is given the same set of images. One group is given the task to assign the image to an animal from a list of animals with ...
-1
votes
1answer
49 views

Finding x and y coordinates from the angle

I have a robot that I am trying to program. I came up with a way to find by how many degrees my arm moved but I want to find a relative $(x , y)$ coordinates. I think that I found the formula: $x = ...
0
votes
2answers
32 views

How can I type this into a calculator?

In a textbook I am asked to calculate an expression using a calculator: $$\frac{1}{2}\ln\left(e^{22}\right)$$ I tried using: 0.5*log(exp**22) This returned an ...
0
votes
1answer
13 views

Computing eigenvectors from a transition matrix

I have a 21x21 transition matrix modeling the population of a species, and I'm trying to find the long term population proportions of the states. To do this, I'm using numpy. I found the dominant ...
0
votes
0answers
32 views

Find taxicab numbers in less than $O(n^2)$ time with number theory into consideration

If seen as an algorithm question, the taxicab numbers can be found in $O(N^2)$. However, I am wondering are there any improvement to get this numbers with less time complexity considering number ...
1
vote
0answers
16 views

BFGS: Wolfe conditions and Algorithm error on absolute values

I debated whether to put this in SO or Mathematics but the problem I suspect is more a mathematical question rather than a programming one. I have a simple objective function: $$f(x) = |x_0| + |x_1| ...
1
vote
1answer
47 views

Newton's method with Gaussian elimination

Implement Newton's method for a system of nonlinear equations $f(x) = 0$, where $f = (f^1,...,f^n)^T = 0$ and $x = (x^1,...,x^n)^T$. Both the function $f$ and the Jacobian $J$ are given as lambda ...
1
vote
1answer
22 views

Finding the y-coordinate of the intersection of two functions when all x-coordinates are unknown

Part 1 I have 2 lines defined by 4 points in a plane: $\overline{(x_1, y_1), (x_2, y_2)}$ and $\overline{(x_3, y_3), (x_4, y_4)}$. I would like to find the $y$-coordinate of the intersection point ...
0
votes
0answers
61 views

How to calculate a weighted probability distribution?

Wikipedia explains a key step in the KMeans++ algorithm as ... "Choose one new data point at random as a new center, using a weighted probability distribution where a point x is chosen with ...
1
vote
0answers
40 views

Connecting Orbits (Heteroclinic Orbits) Between Fixed Points on a Phase Portrait

I was given a ODE system in which I'm needing to solve several things. The ODE is: $v' = v(v-1) + \frac{5}{3}(e - \frac{3}{50}v)$ $e' = v[-\frac{(v-1)^2}{2} + e - \frac{3}{50} + \frac{1}{10}(v-1)]$ ...
10
votes
3answers
2k views

Why is a simulation of a probability experiment off by a factor of 10?

From a university homework assignment: There are $8$ numbered cells and $12$ indistinct balls. All $12$ balls are randomly divided between all of the $8$ cells. What is the probability that there is ...
1
vote
1answer
78 views

SVD and best rank-k

In the following code I am using Python's pillow/PIL library. I have successfully been able to read in an image file and store it as a matrix, access the red, blue, green channel which is an unsigned ...
2
votes
1answer
408 views

How to convert Euler angles to Quaternions and get the same Euler angles back from Quaternions?

I am rotating n 3D shape using Euler angles in the order of XYZ meaning that the object is first rotated along the X axis, then Y...
0
votes
0answers
49 views

Stochastic Differential Equation and Runge-Kutta

I have to solve the Black-Scholes equation, $\textrm{d}X\left(t\right)=\lambda X\left(t\right)\textrm{d}t+\mu X\left(t\right)\textrm{d}W\left(t\right),$ by making use of a RK method (in Python). ...
0
votes
1answer
48 views

How to randomly draw Quaternions within a specific range of Euler angles for rotation?

I am pretty new to Quaternions so please bear with me. I want to draw random Quaternion samples so that their Euler angle equivalent would range within [-30, +30] ...
8
votes
4answers
103 views

How many non-diagonalizable $2\times 2$ matrices are there with all entries single-digit strictly positive integers?

I'd like to know how many non-diagonalizable size 2 matrices there are with integer coefficient between 1 and 9. I built a python program which counts the non-diagonalizable matrices with such ...
0
votes
0answers
27 views

System of linear equations with unknown multidimensional matrix

How to solve systems of linear equations with multidimensional matrices? I have to solve the system like this: $$ \sum_{i'=1}^{L}\sum_{k'=1}^{n} a_{i-i',k'} x_{i',j,k'} = a_{i,j}, $$ $L+1\leq i\leq T$...
0
votes
1answer
55 views

SOR iteration in numerical

In the following code I have made an SOR iteration in python. I seem to be getting the wrong output. It seems to be just outputting the b array when it should be solving the system. Is there something ...
0
votes
1answer
19 views

compute the infinity norm of the difference between the two solutions

In the following code I have been able to: Implement Gaussian elimination with no pivoting for a general square linear system. I have tested it by solving Ax=b, where A is a random 100x100 matrix and ...
1
vote
0answers
25 views

Difference between mathematical interpolation and numerical interpolation?

I have a data set of points. This data is not of full points. Instead, I have to generate a python code using tck = interpolate.bisplrep(xx, yy, zz, s=0) to ...
0
votes
0answers
48 views

Weird visual result for MLE of normal distribution

I am trying to visualize the log likelihood estimator for normal distribution via python but in vain. I am not sure if its a python issue or formuala issue in the code. Can you kindly have a look? ...