我正在尝试为我的机器人制作一个帮助命令(有点花哨),因此我为这些命令做了不同的分类!就像这样- embed = discord.Embed()
embed.title = ":computer: **Help Centre: Meta!**"
embed.description=":pen_ballpoint: Type `am:[command]` to use a command!"
embed.add_field(name="am:hi",value="To say hi to me!")
我正在构建一个函数来计算给定组件/子系统的可靠性。为此,我用脚本编写了以下内容:
import math as m
import numpy as np
def Reliability (MTBF,time):
failure_param = pow(MTBF,-1)
R = m.exp(-failure_param*time)
return R
该函数对于我在函数中调用的任何时间值都很好。现在我想调用函数来计算给定数组的可靠性,比如np.linspace(0,24,25).但是,我得到了诸如"Type :只有length-1数组可以转换为Python标量“之类的错误。
当尝试在python中返回PEB的值时,您会遇到类似的问题,在python中调用__readgsqword是不可能的吗?
def GetPEB():
return ctypes.windll.kernel32.__readgsqword('0x0C',ctypes.sizeof('PVOID'))
AttributeError: function '__readgsqword' not found
在python中,我可以像这样使用正则表达式:
prog = re.compile(pattern)
result = prog.match(string)
我可以result.groups(0),result.groups(0),...等。
如何才能知道结果中有多少组?我尝试了'len(result.groups)',但是我得到了:
TypeError: object of type 'builtin_function_or_method' has no len()
不好意思打扰了,我刚开始学习python编码。我只是在python中自己创建了一些代码,没有错误显示。但是如果语句没有执行为什么。有人能帮忙吗。
代码:
def name(f_name, age):
return f"Hi, {f_name} {age}"
if age <= 18:
print("You are Not eligeble for The post")
else:
print("you are eligeble for post")
person = name(
我有下面的python文件,test.py
from math import floor
from logging import getLogger
当我做以下事情时:
$ python3
>>> import test
>>> help(test)
我看到这个:
Help on module test:
NAME
test
FUNCTIONS
floor(...)
floor(x)
Return the floor of x as an Integral.
This is the lar
%%cython
import numpy as np
cimport numpy as np
def cy_sum(int n):
cdef double s=0
cdef int i
for i in range(n):
s += np.sqrt(i)
return s
如上所示,我有计算平方根和的代码。通过使用cython -a,我得到了图片中的结果。cython代码在函数调用np.sqrt(i)时与python交互,与纯python代码相比没有任何改进。
我不知道在指定变量类型时是否做错了什么。还有其他解决方案,例如使用i*
我用python构建了一个神经网络控制器,并希望使用python函数控制一个simulink模型。我的python函数的输入和输出是'numpy.array‘。输出的形状是4,1。我在simulink中使用了一个'matlab函数‘来调用python函数。matlab函数的代码如下: function [u1, u2, u3, u4] = fcn(data_in)
coder.extrinsic('py.controller.multi_output')
out = 0;
out = py.controller.multi_output(data_in);
u
我在浏览tf2.0文档时,不能理解以下代码的一部分
for units in hidden_units:
x = tf.keras.layers.Dense(units, activation='relu')(x)
outputs = tf.keras.layers.Dense(1, activation='sigmoid')(x)
第二行末尾的(x)是什么意思,它是做什么的?它是TensorFlow的一部分,还是在python中也可用?
我当时正在做我的项目,遇到了这种奇怪的行为。下面的代码演示如何再现它。
class TestClass:
def __init__(self, arr=[]):
self.arr = arr
if __name__ == '__main__':
for i in range(3):
test = TestClass()
test.arr.append('x')
print(test.arr)
我期望得到以下输出:
['x']
['x']
['
如何让这个包含kivy的python代码在另一个包含kivy的python代码中运行,就像你调用一个函数那样,这样我就可以有不同的代码段了。我不想在一个特定的python文件上编写太多的代码,因为我会处理很大的代码。 import kivy
from kivy.app import App
from kivy.uix.floatlayout import Floatlayout
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.label import Label
class
我是ImageJ的新手,我试图用Python重新创建下面的宏(在ImageJ宏编辑器中)。
s = selectionType();
if( s == -1 ) {
exit("There was no selection.");
} else if( s != 10 ) {
exit("The selection wasn't a point selection.");
} else {
getSelectionCoordinates(xPoints,yPoints);
x = xPoints[0];
y =