Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 days ago.
Improve this question
Now I have a differential equation dy/dx = Dx, where D is a matrix with the same number of columns as the number of steps of x to integrate. Different step points x need to be multiplied by the corresponding column in D. How to do this? How to make scipy multiply the different columns in D by the integral of each step in a given interval
I know about this function scipy.integrate.solve_ivp, but I don't know how to define it so that different columns of D correspond to different small integral
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am solving an issue in Python and Pygame (of which I have little knowledge). I am trying to find the way for finding the column x in a 2d rectangular board. I know that to find row y, I would go by:
ind = y * self._num_cols
return self._grid[ind : ind + self._num_cols]
How do I find column x then, without using numPy?
Assuming that it is 1 dimensional, you can do:
return [self._grid[x + i*self._num_cols] for i in range(self._num_cols)]
I know it seems long, but it is just iteratively getting the one in that column for each row.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am struggling to multiply lists as matrices in Python.
I have two lists (weights and returns) and I need to multiply them as: weights*TRANSPOSE(returns).
How are Weights and Return defined in your code?
You might be able to do the following:
#This sums the entries
matrixProduct = 0
for i in range(len(Weights)):
matrixProduct+= Weights[i]*Return[i]
#In case you meant to keep products of individual pairs of matrix entries (not sure from your notation):
matrixProduct = []
for i in range(len(Weights)):
matrixProduct.append(Weights[i]*Return[i])
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm wondering how I can calculate powers of a complex number without using the complex numbers data type. So I have a function
def Power_complex(re, im, n):
How can I calculate (re + im * i)^n with this? Thank you!
You can use the Biniomial theorem for arbitrary exponents, although positive integers is the easiest case.
Or you can treat the problem in polar coordinates (this link simply gives you the answer, only click if you really don't want to figure it out on your own)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have two columns (2x10) of data the first column is the data the second is the errors. I want to generate the gaussian distribution value for each value in first column taking it with corresponding errors. So how can I manage that?
Try this
# Your array of data and measurements
measurements = np.ones((10,2))
# 10 values drawn from a Gaussian distribution
measurements[:,1] = np.random.normal(0.0,1.0,size=(10,1))
Where np.random.normal(0.0, 1.0, 1) draws a single value from a Gaussian distribution with a mean of 0 and a standard deviation of 1.0. See the docs for more information.
The third argument in my code above, denoted by size, gives you the shape of the array of samples you require.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have been wanting to know how can I get a line of Python code that uses the uniform() function such as:
X_test = uniform(0, 1, size=(test_size, 20))
where test size is 1000 observations and 20 predictors, into an R code version. Much appreciated thanks!
Assuming you want a function that takes a random sample from a uniform distribution, there is an R function for that:
https://stat.ethz.ch/R-manual/R-devel/library/stats/html/Uniform.html
Specifically, use the runif function to generate n random samples from min to max.
In your case, you could generate a 1000 by 20 matrix of uniform samples using the following code:
matrix(runif(test_size * predictors), ncol=predictors)