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.
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 8 months ago.
Improve this question
Given an array update the second column by the square root of those values.
As rafaelc suggested, you can use np.sqrt on a specific column.
a = np.array([[1.,2.,3.],[1.,2.,3.]])
a[:,1] = np.sqrt(a[:,1])
a has two rows and three columns. a[:,1] is the second column.
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 last year.
Improve this question
I have an string in python (with float and integer numbers)
string = '44,44,44,33'
I want to calculate the mean of that.
Note: I have one large dataframe, and in one column of the dataframe, I have such a string. I want to calculate the mean for all rows. I hope I there is an efficient way for that.
Thanks
Spilt string, covert to integers, and calculate mean:
import statistics
result = statistics.mean(map(int, string.split(",")))
l = string.split(',')
average = sum(int(k) for k in l)/len(l)
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 am doing an assignment for class and have this question: "Create a target array gap for bandgap - the difference between lumo_zindo and homo_zindo." I do not understand or know what they are asking. In class, we simply learned how to plot multilinear regression so I have no clue what gap or bandgap are.
Wikipedia goes a long way toward explaining your question about lumo_zindo and homo_zindo.
They're referring to electron orbitals. HOMO is the Highest Occupied Molecular Orbital. LUMO is the Lowest Occupied Molecular Orbital. The Band Gap is the Energy delta between the two.
Check out the links for reference:
https://en.wikipedia.org/wiki/HOMO_and_LUMO
https://en.wikipedia.org/wiki/ZINDO
As far as creating the gap Array in python (assuming lumo_zindo and homo_zindo are both lists that contain the same numeric data type), I'd try:
gap = []
for h,l in zip(homo_zindo, lumo_zindo):
gap.append(h - l)