# 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.

298 questions
37 views

### Use matplotlib to plot the functions $y = x^3 + 3x^2 - x + 0.3\$ and $y = \sin x$

I'm new to Python coding and wondered if someone could give me the coding to plot these two graphs on the same program. This is what I have so far, exactly as typed on Python, however I know that ...
18 views

### Binomial Probability Number of Trials Formula and Code

This is an interview question I've had. Your number space is between 0 to N. You can only draw M random samples from 0 to N (N >= M). How many times (T) would you need to draw from your number space ...
9 views

### How to vectorize/matricize multivariate Gaussian PDF for more efficient computation?

Context: I was recently implementing (in Python) the Expectation-Maximization (EM) algorithm for Gaussian mixture models, and part of that process involves computing the Gaussian PDF for various ...
44 views

### How can I form in python this matrix to the corresponding graph?

im working in graph theory and sagemath or python. for prove that $R(3,3)=6$ is necessary to find a counterexample of a graph where it has neither a triangle monochromatic red nor a $K_3$ blue, for ...
55 views

### Hackerrank matchstick experiment

The problem is regarding probability. The problem is given in detail here. In an $m \times n$ grid, $2mn -m -n$ matchsticks are placed at the inner boundaries between squares on the grid. We can ...
10 views

### Facing error - catalyst.utils while running algorithm…in pycharm [on hold]

from catalyst.utils.run_algo import run_algorithm def initialize(context): context.bittrex=context.exchanges['bitfinex'] context.poloniex = context.exchanges['poloniex'] ...
17 views

### Find boundaries to separate peaks in a 3D plot using matlab or python

Could you tell me how to find boundaries to separate the peaks in the 3D plot below? Ideally, the boundaries are at the local minimum. Peaks can be generated using Gaussian distributions with some ...
38 views

### How can I calculate Feigenbaum's constant?

So I am trying to calculate Feigenbaum's constant for the logistic map: $$x_{n+1} = 4 \lambda x_n (1-x_n)$$ I am writing this through python and the main pieces I have for my code that are relevant ...
11 views

### quadratic bezier to parabola matrix equation

I'm trying to follow the matrix equation solution presented here: Convert quadratic bezier curve to parabola by @robjohn I'm assuming his solution can be used for any quadratic coordinates. My goal ...
61 views

### Inverse Matrix in Python

My understanding is that I can use Python to initialize my matrix and then apply an inverse function to find the solution.
17 views

### Correct notation for broadcasting operation

In Python numpy a row vector $u \in \mathbb{R}^n$ and its transposed $u^T$ can be added, multiplied or subtracted, yielding a $\mathbb{R}^{n\times n}$ matrix, where each element $(i,j)$ is the ...
44 views

### How to implement boundary value in Python using spectral methods

I want to solve the heat equation $$u_t=au_{xx},\quad 0\leq t, \ 0\leq x\leq\pi$$ in Python using spectral methods. I set $u(0,x)=\sin(x)$ as initial value for the time and choose $a=2$. My Code: <...
16 views

### How would I get the Heaviside function to be period in my solution?

so I am trying to solve an RC circuit problem that represents the square wave. Which I have already done on paper and now I am trying to plot it. So for this problem, we solved it using two methods, ...
49 views

### how to work out a computer program running time

I have a question and im not sure how to tackle it.... algorithms have running times proportional to the following functions of the input size, denoted N: $N^2$ $2^N$ In one minute of computing ...
88 views

11 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. ...
49 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 ...
35 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 ...
23 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 ...
393 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....
43 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 ...
64 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, ...
55 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 ...
86 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 ...
35 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 (...
51 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 ...
36 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. ...
59 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 ...
67 views

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}... 1answer 25 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 ...