简体   繁体   English

使用 np.ndarray 调用函数说“类型错误:缺少 1 个必需的位置参数:”

[英]Function call with np.ndarray say "TypeError: missing 1 required positional argument: "

I'm writing the code to rotate matrix(1x3) on Python 3.5.2.我正在编写代码以在 Python 3.5.2 上旋转矩阵(1x3)。

To rotate matrix, I made a function.(Not a Class)为了旋转矩阵,我做了一个函数。(不是一个类)

def rotate_rpy(posvec: Vector, rotvec: Vector) -> Vector :
  return np.dot(np.dot(np.dot (posvec, rotate_rpy(rotvec[0]) ), rotate_pitch(rotvec[1]) ), rotate_yaw(rotvec[2]))

newpose = rotate_rpy(mypose, rotateang)#enbug

it is getting an Error like this它收到这样的错误

Traceback (most recent call last): 
  File "rotation_matrix.py", line 50, in <module>
    newpose = rotate_rpy(mypose, rotateang)#enbug
  File "rotation_matrix.py", line 35, in rotate_rpy
    return np.dot(np.dot(np.dot (posvec, rotate_rpy(rotvec[0]) ), rotate_pitch(rotvec[1]) ), rotate_yaw(rotvec[2]))
TypeError: rotate_rpy() missing 1 required positional argument: 'rotvec'

maybe a silly question, but I dont Understand what is the problem.也许一个愚蠢的问题,但我不明白是什么问题。

Most question on the Internet says something about instantiate, but it is just a function.互联网上的大多数问题都是关于实例化的,但它只是一个函数。 not class.不上课。 Anyways I just tried changing argument:无论如何,我只是尝试改变论点:

newpose = rotate_rpy(mypose, mypose, rotateang)#enbug

then然后

TypeError: rotate_rpy() takes 2 positional arguments but 3 were given

and

newpose = rotate_rpy(mypose)#enbug

then然后

TypeError: rotate_rpy() missing 1 required positional argument: 'rotvec'

I trust it silly but我相信它很傻但是

newpose = rotate_rpy()#enbug

then然后

TypeError: rotate_rpy() missing 2 required positional arguments: 'posvec' and 'rotvec'

I'm confuced我很困惑

3 arg - too much arg 3 arg - 过多的 arg

2 arg - 1 arg misssing 2 arg - 1 arg 缺失

1 arg - 1 arg missing 1 个参数 - 1 个参数丢失

0 arg - 2 arg missing 0 arg - 2 arg 丢失

It isn't corresponding.不是对应的。 I have no idea.我不知道。 Please help me...请帮我...

Full Code Below:完整代码如下:

#coding:utf-8

import numpy as np

def rotate_roll (th):
  _rot_vec_roll = {
    { 1.,          0. ,         0.},
    { 0.,   np.cos(th), np.sin(th)},
    { 0., - np.sin(th), np.cos(th)}
  }
  return _rot_vec_roll

def rotate_pitch (th):
  _rot_vec_pitch = {
    {  np.cos(th),0. , np.sin(th)},
    {  0.,        1.,          0.},
    {- np.sin(th),1.,  np.cos(th)}
  }
  return _rot_vec_pitch

def rotate_yaw (th):
  _rot_vec_yaw = {
    {   np.cos(th), np.sin(th), 0.},
    { - np.sin(th), np.cos(th), 0.},
    {           0.,         0., 1.}
  }
  return _rot_vec_yaw

# R2 = A * R1 
# A = roll_vec * pitch_vec * yaw_vec

Vector = np.ndarray(shape=(1,3), dtype=np.float)

def rotate_rpy(posvec: Vector, rotvec: Vector) -> Vector :
  return np.dot(np.dot(np.dot (posvec, rotate_rpy(rotvec[0]) ), rotate_pitch(rotvec[1]) ), rotate_yaw(rotvec[2]))

mypose = np.ndarray(shape=(1,3), dtype=np.float)
mypose = np.array([3.0,1.0,1.0], dtype=float)

print(mypose)

base = np.pi / 6.0

rotateang = np.ndarray(shape=(1,3), dtype=np.float)
rotateang = np.array([base, base/2.0, base], dtype=float)

print(rotateang)

newpose = np.ndarray(shape=(1,3), dtype=np.float)
newpose = rotate_rpy(mypose, rotateang)#enbug
print(newpose);

and full error below:和下面的完整错误:

[ 3.  1.  1.]
[ 0.52359878  0.26179939  0.52359878]
Traceback (most recent call last):
  File "rotation_matrix.py", line 50, in <module>
    newpose = rotate_rpy(mypose, rotateang)#enbug
  File "rotation_matrix.py", line 35, in rotate_rpy
    return np.dot(np.dot(np.dot (posvec, rotate_rpy(rotvec[0]) ), rotate_pitch(rotvec[1]) ), rotate_yaw(rotvec[2]))
TypeError: rotate_rpy() missing 1 required positional argument: 'rotvec'

The function rotate_rpy is defined to call itself infinitely recursively (which is a problem on its own):函数rotate_rpy被定义为无限递归地调用自己(这本身就是一个问题):

def rotate_rpy(posvec, rotvec):
    return np.dot(np.dot(np.dot (posvec, rotate_rpy(rotvec[0]), ....)

It also calls itself inconsistently, with only one parameter.它也不一致地调用自己,只有一个参数。 Python interpreter cannot catch the first error by fortunately reports the second error. Python 解释器无法通过幸运地报告第二个错误来捕获第一个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的函数说 np.ndarray 对象不可调用? - Why does my function say np.ndarray object not callable? 为什么会这样说:“类型错误:__call__() 缺少 1 个必需的位置参数:‘输入’” - why does it say this: "TypeError: __call__() missing 1 required positional argument: 'inputs'" 将函数应用于np.ndarray? - apply a function to np.ndarray? np.ndarray 由 np.ndarray 索引 - np.ndarray is indexed by np.ndarray TypeError:EnumMeta.__call__() 缺少 1 个必需的位置参数:“值” - TypeError: EnumMeta.__call__() missing 1 required positional argument: 'value' 类型错误:在调用 super.__init__() 时缺少 1 个必需的位置参数 - TypeError: missing 1 required positional argument in call to super.__init__() 类型错误:__call__() 缺少 1 个必需的位置参数:“输入” - TypeError: __call__() missing 1 required positional argument: 'inputs' TypeError:AsyncConsumer.__call__() 缺少 1 个必需的位置参数:'send - TypeError: AsyncConsumer.__call__() missing 1 required positional argument: 'send python Tkinter 调用 function 在 class 之间调用 function - python Tkinter call function between class gets TypeError __init__() missing 1 required positional argument: 'parent' Class 中的 Function 错误:TypeError:函数()缺少 1 个必需的位置参数: - Function in Class error: TypeError: function() missing 1 required positional argument:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM