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 13 hours ago.
Improve this question
When a variable is normalized, its value will change and its sum will be 1. However, the value obtained when the variable is later substituted does not change. Can anyone help to solve this problem? Let's put the specific example below. Normalize fy, y does not change, no matter yF will change, but dy has not changed. I hope you can solve this problem.
fy_ = 0
for i in range(len(fy)):
fy_ += fy[i]
fy = fy / fy_
print(sum(fy))
yF = 0
for i in range(len(y) - 1):
yF += (y[i + 1] -y[i]) * (y[i] * fy[i])
print(yF)
dy = y * fy / yF
print(dy)
I have used different y, fy has tried many times, and every time dy basically does not change, which makes me wonder why this phenomenon occurs
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 3 months ago.
Improve this question
I must've skipped school that day because I cannot remember how to calculate the middle of a square.
There are a few different ways to calculate the middle of a square using Python. One way is to find the average of the x and y coordinates of the square's four corners. Another way is to find the point that is equidistant from all four corners of the square.
# method-1
def square_middle(square):
x1, y1, x2, y2 = square
return ((x1 + x2) / 2, (y1 + y2) / 2)
# method-2
def square_middle(square):
x1, y1, x2, y2 = square
cx = (x1 + x2) / 2
cy = (y1 + y2) / 2
return (cx, cy)
frameworks usually report the size of a screen with 2 values or a touple of 2. For example, this is how pyautogui reports it:
print(pyautogui.size())
Size(width=1728, height=1117)
And this is how that framework gets the center for every coordinates tuple:
https://github.com/asweigart/pyscreeze/blob/master/pyscreeze/__init__.py#L579
So you can safely use the example above to get the center of any object on screen, even the screen itself.
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 need to understand how numpy.interp function works. This function has a couple of parameters which are vague to me, like: xp, fp, left and right.
I saw an example of this function as below:
X is a numpy ndarray and y is one-dimensional array:
X = np.interp(X, (X.min(), X.max()), (0, 10))
y = np.interp(y, (y.min(), y.max()), (30000, 100000))
Thanks for helping me out!
x are the points which are not in xp but you want their y values i.e. points where you want to perform interpolation
xp and yp are the main inputs based on which 1D interpolation works (these are the discrete data points through which you want to interpolate)
left and right handle the edge case scenarios when x is out of the closed interval range of [xp_minimum, xp_maximum] i.e. the output values to generate incase of extrapolation
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 5 years ago.
Improve this question
I have a map where they find several points (lat/long) and want to know the distance that exists between them.
So, given a set of lat/long coordinates, how can I compute the distance between them in python?
I once wrote a python version of this answer. It details the use of the Haversine formula to calculate the distance in kilometers.
import math
def get_distance(lat_1, lng_1, lat_2, lng_2):
d_lat = lat_2 - lat_1
d_lng = lng_2 - lng_1
temp = (
math.sin(d_lat / 2) ** 2
+ math.cos(lat_1)
* math.cos(lat_2)
* math.sin(d_lng / 2) ** 2
)
return 6373.0 * (2 * math.atan2(math.sqrt(temp), math.sqrt(1 - temp)))
Ensure the coordinates being passed to the function are in radians. If they're in degrees, you can convert them first:
lng_1, lat_1, lng_2, lat_2 = map(math.radians, [lng_1, lat_1, lng_2, lat_2])
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 7 years ago.
Improve this question
I am using SimpleGui and pygame modules to develop a game on python. I have a line and its coordinates as shown below:
I am interested in moving the line diagonally in the direction of an arrow for which I will require to update the coordinates before drawing it on canvas. I am confused as how to update the x and y coordinates to move the line in desired direction.
You have to choose N to get step size
dx = (x1-x2)/N
dy = (y1-y2)/N
and then you can move
x1 += dx
y1 += dy
x2 += dx
y2 += dy
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 years ago.
Improve this question
I have a loop
for i in range(0,1000,100):
and inside it I compute a list which holds 10 values but the loop goes from 0 to 1000.I want to relate these 10 values with the 1000 values; namely, create a list (or array) which will hold these values (the 10 to 1000 values).
UPDATED------------------------------------------
I want to make a plot which will have in the horizontal axis values from 0 to 1000 and in the vertical axis the 10 values of the list that i computed.
Your question is very unclear.
From your comment it seems like you're asking about matplotlib? Do you want something like this?
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0, 1000, 100)
# As a placeholder for your calculation...
y = np.cos(x / 100.0)
plt.plot(x, y, marker='o', mfc='red')
plt.show()
Do you want to access the list elements while retaining the range from 0 to 1000 in steps of 100? If so, this should be a way.
mylst=[12,5,6,34,6,11,78,1,1,88]
for i in range(0,1000,100):
print mylst[i/100]
Not sure... a more detailed question could help.