2017-08-06 12 views
-1

PyCallドキュメント: 重要:Pythonとの最大の違いは、オブジェクト属性/メンバーはoではなくo [それで、Pythonのo.method(...)はJuliaのo:methodに置き換えられました。また、o [key]ではなくget(o、key)を使用します。 (ただし、0ベースのPythonインデックスではなく、1ベースのジュリアンインデックスでも、Pythonのようにo [i]で整数インデックスにアクセスできます)PyCallを使用してjuliaでisinstance()のようなPython組み込み関数を使用するにはどうすればよいですか?

しかし、どのモジュールまたはオブジェクトをインポートするのか分かりません。

ここで
+1

を始めるために簡単な例です。これを行う方法:a)あなたのコードをいくつか追加します。 b)あなたの関数の目的が何であるか、それが何を計算しようとしているのかを説明してください。 c)共有するコードを実行可能にし、おそらく結果やエラーを追加してください。 d)質問である文(最後に?)を追加し、答えが何であるかを記述しようとする。 (a)、(b)、(c)、(d)の任意の組み合わせが役立ちます。 –

+0

とにかく、ありがとう、最初の答えは私の問題を解決しました。 –

答えて

2

は、あなたが質問をより明確に

using PyCall 

@pyimport numpy as np   # 'np' becomes a julia module 

a = np.array([[1, 2], [3, 4]]) # access objects directly under a module 
           # (in this case the 'array' function) 
           # using a dot operator directly on the module 
#> 2×2 Array{Int64,2}: 
#> 1 2 
#> 3 4 

a = PyObject(a)     # dear Julia, we appreciate the automatic 
           # convertion back to a julia native type, 
           # but let's get 'a' back in PyObject form 
           # here so we can use one of its methods: 
#> PyObject array([[1, 2], 
#>     [3, 4]]) 

b = a[:mean](axis=1)   # 'a' here is a python Object (not a python 
           # module), so the way to access a method 
           # or object that belongs to it is via the 
           # pythonobject[:method] syntax. 
           # Here we're calling the 'mean' function, 
           # with the appropriate keyword argument 
#> 2-element Array{Float64,1}: 
#> 1.5 
#> 3.5 

pybuiltin(:type)(b)    # Use 'pybuiltin' to use built-in python 
           # commands (i.e. commands that are not 
           # under a module) 
#> PyObject <type 'numpy.ndarray'> 

pybuiltin(:isinstance)(b, np.ndarray) 
#> true 
+0

ありがとう、あなたの答えは私の問題を完全に解決しました –

関連する問題