如何使用CSS创建点线或任何类型的hr线(双线,虚线等)?
<hr style="...what should I write?..." />
Run Code Online (Sandbox Code Playgroud)
或者还有其他伎俩吗?
所以,我在Python中的polyfit(numpy.polynomial.polynomial.polyfit)函数中查找了有关weights参数的信息,看起来它与与各个点相关的错误有关.(如何在numpy.polyfit中包含测量误差)
但是,我想要做的与错误无关,而是权重.我有一个numpy阵列形式的图像,表明探测器中沉积的电荷量.我将该图像转换为散点图,然后进行拟合.但我希望这适合给予更多电荷沉积的点更多的权重,而不是那些电荷更少的点.这是权重参数的用途吗?
def get_best_fit(image_array, fixedX, fixedY):
weights = np.array(image_array)
x = np.where(weights>0)[1]
y = np.where(weights>0)[0]
size = len(image_array) * len(image_array[0])
y = np.zeros((len(image_array), len(image_array[0])))
for i in range(len(np.where(weights>0)[0])):
y[np.where(weights>0)[0][i]][np.where(weights>0)[1][i]] = np.where(weights>0)[0][i]
y = y.reshape(size)
x = np.array(range(len(image_array)) * len(image_array[0]))
weights = weights.reshape((size))
b, m = polyfit(x, y, 1, w=weights)
angle = math.atan(m) * 180/math.pi
return b, m, angle
Run Code Online (Sandbox Code Playgroud)
让我向您解释一下代码:
第一行将指定的电荷分配给称为权重的变量.接下来的两行得到沉积电荷> 0的点,因此存在一些电荷以捕获散射图的坐标.然后我得到整个图像的大小,以便稍后转换为一维数组进行绘图.然后我去通过图像,并试图让那里的一些电荷堆积的点的坐标(记住,量电荷时,存储在变量weights).然后我重塑y坐标以获得一维数组,并从图像中获取所有相应y坐标的x坐标,然后将权重的形状也改变为一维.
编辑:如果有使用该np.linalg.lstsq函数的方法,这将是理想的,因为我也试图通过绘图的顶点.我可以重新定位绘图,使顶点为零,然后使用np.linalg.lstsq,但这不允许我使用权重.
[代码取自Mark Lutz编程Python第4版]
"forks child processes until you type 'q'"
import os
def child():
print('Hello from child', os.getpid())
os._exit(0) # else goes back to parent loop
def parent():
while True:
newpid = os.fork()
if newpid == 0:
child()
else:
print('Hello from parent', os.getpid(), newpid)
if input() == 'q': break
parent()
Run Code Online (Sandbox Code Playgroud)
运行时代码输出的内容:
Hello from parent 2057 2062
Hello from child 2062
Hello from parent 2057 2068
Hello from child 2068
Hello from parent 2057 2069
Hello from child 2069
Hello from parent …Run Code Online (Sandbox Code Playgroud) 我在3D空间中有一组x,y,z点,另一个变量叫做charge表示在特定的x,y,z坐标中沉积的电荷量.我想对这个数据进行加权(通过检测器中沉积的电荷量加权,这对应于更高的重量以获得更多电荷),使得它通过给定点即顶点.
现在,当我为2D做这个时,我尝试了各种方法(将顶点带到原点并对所有其他点进行相同的变换,并强制拟合穿过原点,给出顶点非常高的权重)但是没有一个像Jaime在这里给出的答案一样好:如何用固定点进行多项式拟合
它使用拉格朗日乘数的方法,我从本科高级多变量课程中模糊地熟悉,但其他并不多,看起来这个代码的转换就像添加az坐标一样简单.(请注意,即使代码没有考虑到沉积的电荷量,它仍然给我最好的结果).我想知道是否有相同算法的版本,但是在3D中.我还在Gmail中联系了答案的作者,但没有收到他的回复.
以下是有关我的数据的更多信息以及我在2D中尝试做的事情:如何权衡散点图中的点以获得拟合?
这是我执行此操作的代码,其中我强制顶点位于原点,然后适合数据设置fit_intercept=False.我目前正在研究2D数据的这种方法,因为我不确定拉格朗日乘数是否有3D版本,但是在3D中有线性回归方法,例如,这里:在3D中拟合一条线:
import numpy as np
import sklearn.linear_model
def plot_best_fit(image_array, vertexX, vertexY):
weights = np.array(image_array)
x = np.where(weights>0)[1]
y = np.where(weights>0)[0]
size = len(image_array) * len(image_array[0])
y = np.zeros((len(image_array), len(image_array[0])))
for i in range(len(np.where(weights>0)[0])):
y[np.where(weights>0)[0][i]][np.where(weights>0)[1][i]] = np.where(weights>0)[0][i]
y = y.reshape(size)
x = np.array(range(len(image_array)) * len(image_array[0]))
weights = weights.reshape((size))
for i in range(len(x)):
x[i] -= vertexX
y[i] -= vertexY
model = sklearn.linear_model.LinearRegression(fit_intercept=False)
model.fit(x.reshape((-1, 1)),y,sample_weight=weights)
line_x = np.linspace(0, 512, 100).reshape((-1,1))
pred …Run Code Online (Sandbox Code Playgroud) 该代码取自Mark Lutz的Learning Python第4版
class tracer:
def __init__(self, func):
self.calls = 0
self.func = func
def __call__(self, *args):
self.calls += 1
print('call %s to %s' % (self.calls, self.func.__name__))
self.func(*args)
@tracer
def spam(a, b, c):
print(a + b + c)
spam(1, 2, 3)
Run Code Online (Sandbox Code Playgroud)
此外,当我运行此代码时,它也不会打印1,2,3的总和,但在书中,它表明它确实如此!我对整个代码感到头疼.我不知道这里发生了什么.
我需要像在Khanacademy或Edx这样的网站上进行一些实施 - 当你重新登录时,他们告诉你,"你目前在这一部分,继续从这里开始?"
我能想到这样做的唯一方法是在数据库中有一个列,并为每个部分都有一个表单(如第1课,第2课,第3课),每当用户点击该部分时,表单都会被提交并且更新数据库中的列以便记住.这种方法会起作用还是有更好的方法呢?
我正在使用PHP构建一个网站,我需要验证用户输入的名称是否正确.由于JavaScript是客户端的,我不能完全依赖它,所以这是我的服务器端函数来验证用户名:
function validate_name($name) {
$name = trim($name); // only for the purpose of debugging <---- edited comment
echo $name;
if (strlen($name) <= 1) {
return "small";
} else if (has_numbers($name)) {
return "numbers";
} else {
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
在此之后,我相应地检查输入和显示结果:
function final_check() {
if (validate_name($_POST["first_name"]) == "small") {
echo "<span class='error'>Your first name cannot be empty</span>";
return false;
} else if (validate_name($_POST["first_name"]) == "numbers") {
echo "<span class='error'>Numbers are not allowed in your first name</span>";
return false;
}
return …Run Code Online (Sandbox Code Playgroud)