2017-08-29 15 views
0

こんにちは、関数に変数の束を呼び出そうとしていますが、numpy.nadarrayエラーがスローされ続けます。問題の"numpy.ndarrayはオブジェクトが呼び出し可能ではありません"というエラーが発生しました。

機能:

def alpha(rotate_axis,angle): 
    rotate_axis = (input("What the is the axis of rotation? x1, x2 or x3 ")) 
    angle = int(input("What is the angle of rotation in degrees?")) 
    #transforming deg -> rad 
    angle_r = radians(angle[0]) 
    cos = np.cos(angle_r) 
    sin = np.sin(angle_r) 

    if rotate_axis == "x1": 
     rotation = np.array([[1,0,0],[0,cos,-sin],[0,sin,cos]]) 
    elif rotate_axis == "x2": 
     rotation = np.array([[cos, 0, sin], [0, 1, 0], [-sin,0, cos]]) 
    elif rotate_axis == "x3": 
     rotation = np.array([[cos, -sin, 0], [sin, cos, 0], [0, 0, 1]]) 

    #print("Direction cosines:",rotation) 

    #producing alpha matrix 
    #decomposing rotation consines 
    a11 = rotation[0][0] 
    a12 = rotation[0][1] 
    a13 = rotation[0][2] 
    a21 = rotation[1][0] 
    a22 = rotation[1][1] 
    a23 = rotation[1][2] 
    a31 = rotation[2][0] 
    a32 = rotation[2][1] 
    a33 = rotation[2][2] 
    alpha = np.array([[ a11**2, a12**2, a13**2, 2*a12*a13, 2*a13*a11, 2*a11*a12], 
        [ a21**2, a22**2, a23**2, 2*a22*a23, 2*a23*a21, 2*a21*a22], 
        [ a31**2, a32**2, a33**2, 2*a32*a33, 2*a33*a31, 2*a31*a32], 
        [ a21*a31, a22*a32, a23*a33, a22*a33 + a23*a32, a21*a33 + a23*a31, a22*a31 + a21*a32], 
        [ a31*a11, a32*a12, a33*a13, a12*a33 + a13*a32, a13*a31 + a11*a33, a11*a32 + a12*a31], 
        [ a11*a21, a12*a22, a23*a33, a12*a23 + a13*a32, a13*a21 + a11*a23, a11*a22 + a12*a21], 
       ]) 
    return alpha 

これは私が(エラーがスローされます)関数を呼び出している

alpha_110 = alpha("x3",45) 
+0

おそらく、返された変数alphaの名前を変更する必要があります。 –

+0

'return'変数を関数の名前以外に変更してください。 'alpha alpha'を使うと、' alpha = np.array(...) 'で作成した' alpha'配列の値を必ずしも返すわけではないので、 'def alpha(。 ..): ' –

+0

@DanielF return文はローカル変数' alpha'と同じスコープにあります。私はその機能をどのように戻すことができるのか本当に分かりません。 'numpy.ndarray'は呼び出し可能ではないというメッセージには言及されていません。 –

答えて

2

は、このコードとPython 3.6と私のためのエラーなし: 私は取りませんでした入力を開始するたびに入力によって値を消去すると、rotate_axisとangleをパラメータとして持つことは全く無意味です。

# -*-coding:Utf-8 -* 

# Import des packages 
import numpy as np 
from math import radians 
import os 

def alpha(rotate_axis,angle): 

    #transforming deg -> rad 
    angle_r = radians(angle) 
    cos = np.cos(angle_r) 
    sin = np.sin(angle_r) 

    if rotate_axis == "x1": 
     rotation = np.array([[1,0,0],[0,cos,-sin],[0,sin,cos]]) 
    elif rotate_axis == "x2": 
     rotation = np.array([[cos, 0, sin], [0, 1, 0], [-sin,0, cos]]) 
    elif rotate_axis == "x3": 
     rotation = np.array([[cos, -sin, 0], [sin, cos, 0], [0, 0, 1]]) 

    #print("Direction cosines:",rotation) 

    #producing alpha matrix 
    #decomposing rotation consines 
    a11 = rotation[0][0] 
    a12 = rotation[0][1] 
    a13 = rotation[0][2] 
    a21 = rotation[1][0] 
    a22 = rotation[1][1] 
    a23 = rotation[1][2] 
    a31 = rotation[2][0] 
    a32 = rotation[2][1] 
    a33 = rotation[2][2] 
    alpha = np.array([[ a11**2, a12**2, a13**2, 2*a12*a13, 2*a13*a11, 2*a11*a12], 
        [ a21**2, a22**2, a23**2, 2*a22*a23, 2*a23*a21, 2*a21*a22], 
        [ a31**2, a32**2, a33**2, 2*a32*a33, 2*a33*a31, 2*a31*a32], 
        [ a21*a31, a22*a32, a23*a33, a22*a33 + a23*a32, a21*a33 + a23*a31, a22*a31 + a21*a32], 
        [ a31*a11, a32*a12, a33*a13, a12*a33 + a13*a32, a13*a31 + a11*a33, a11*a32 + a12*a31], 
        [ a11*a21, a12*a22, a23*a33, a12*a23 + a13*a32, a13*a21 + a11*a23, a11*a22 + a12*a21], 
       ]) 
    return alpha 

alpha_110 = alpha("x3",45) 
print (alpha_110) 
os.system("pause") 
関連する問題