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
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 have following for loop to extract bounding boxes in an image. Assuming the p is the center point of each box.
The distance formula is: √[(x₂ - x₁)² + (y₂ - y₁)²]. This works for any two points in 2D space with coordinates (x₁, y₁) for the first point and (x₂, y₂) for the second point. You can notice that it is Pythagoras theorem and the distance is the hypotenuse, and the lengths of the sides are the difference between the x and y components of the points.
So once you have p (center point of bounding box) for two boxes you need to just apply the formula. You can also create a loop and do that for all the p variables that you calculate depending on how many boxes you have.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I try to plot a sinus function. But it throws an error" x and y must have same first dimension, but have shapes (1,) and (51,)" I can't understand they have same dimension. Why do I get this error? Thanks in advance.
%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
from math import pi
from numpy import *
# spatial domain
xmin = 0
xmax = 1
n = 50 # num of grid points
# x grid of n points
x = np.linspace(xmin, xmax, n+1);
k=2
def f1(x):
return np.sin(2*pi*k*x)
plt.plot(f1,x)
Change the bottom of your program to be semantically correct:
plt.plot(f1(x),x)
plt.show()
f1 is a function object; f1(x) is a vector of return values.
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 years ago.
Improve this question
I have an numpy array image which contain circles. I extracted the whole x,y centroids (in pixels) of these circles (a numpy array as well). Now, I want to crop a square around each x,y centroid.
Can someone instruct me how to solve it?
Note that I didn't find any question in Stack that deals with crop around a specific coordinate.
Thank you!
If your centroid has indices i,j and you want to crop a square of size 2*w+1 around it on a numpy array a, you can do
a[i-w:i+w+1,j-w:j+w+1]
This is provided your indices are always more than w from the boundary.
If they're not, you can do
imin = max(0,i-w)
imax = min(a.shape[0],i+w+1)
jmin = max(0,j-w)
jmax = min(a.shape[1],j+w+1)
a[imin:imax,jmin:jmax]
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 7 years ago.
Improve this question
Need help with this of python
Write a program with 3 functions to find out the
(function 1) dot product, (function 2) angle, and
(function 3) cross product of two vectors.
Program should ask a user to input three
points in 3D space such as (x1, y1, z1), (x2,
y2, z2) (x3, y3, z3).
Find two vectors
Find dot product,
Find the angle between two vectors
Find the cross product of two vectors
You will need to import library visual to use the following functions.
Given vector v1 and v2:
To find the angle:
diff_angle(v1,v2)
or
v1.diff_angle(v2)
This gives the angle in radians.
To get the dot product:
dot(v1,v2)
can also be written as:
mag(v1)*mag(v2)*cos(diff_angle(v1,v2))
or
v1.dot(v2))
To find cross product:
cross(v1,v2)
or:
mag(v1)*mag(v2)*sin(diff_angle(v1,v2))
or:
v1.cross(v2)
Given two point p1 and p2, to find vector fromp1top2`:
vector(p2)-vector(p1)
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.