Numpy/Python 数组值错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42891965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Numpy/Python Array Value error
提问by AnthonyT
I am trying to create a function to calculate the end-effector position of robotic arm using numpy arrays, but am coming across an error when the code runs. I have a function that passes in angles as arguments.
我正在尝试创建一个函数来使用 numpy 数组计算机械臂的末端执行器位置,但是在代码运行时遇到错误。我有一个将角度作为参数传递的函数。
def FinalPosition(angle1, angle2, angle3, angle4, angle5, angle6):
My IDE is highlighting the last two lines of the array:
我的 IDE 突出显示了数组的最后两行:
T1 = np.array([np.cos(angle1), -np.sin(angle1)*np.cos(b1), np.sin(angle1)*np.sin(b1), a1*np.cos(angle1)],
[np.sin(angle1), np.cos(angle1)*np.cos(b1), -np.cos(angle1)*np.sin(b1), a1*np.sin(angle1)],
[0, np.sin(b1), np.cos(b1), d1],
[0, 0, 0, 1])
and the error i'm getting is:
我得到的错误是:
.............................................in FinalPosition
[0, np.sin(b1), np.cos(b1), d1], [0, 0, 0, 1])
ValueError: only 2 non-keyword arguments accepted
Not sure what the issue is, could someone explain?
不知道是什么问题,有人能解释一下吗?
edit: the IDE hightlight over the last two lines says this.
编辑:最后两行的 IDE 高亮显示了这一点。
Expected type 'Optional[bool]', got 'List[Union[int | TypeVar('T'), Any]]' instead less... (Ctrl+F1 Alt+T)
This inspection detects type errors in function call expressions. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Types of function parameters can be specified in docstrings or in Python 3 function annotations.
此检查检测函数调用表达式中的类型错误。由于动态调度和鸭子类型,这在有限但有用的情况下是可能的。函数参数的类型可以在文档字符串或 Python 3 函数注释中指定。
回答by AnthonyT
Answered by @hpaulj and @ForceBru in the comments. Missing a set of [] brackets.
由@hpaulj 和@ForceBru 在评论中回答。缺少一组 [] 括号。
np.array([ your lists ])