2016-08-31 4 views
0

私は現在、PyObjectリストを取り、PySequence_Fastを使って解析することができるPython C拡張を持っています。numpy配列をC++のネイティブベクトルに変換する

1次元の配列を解析するのに相当するコマンドはありますか? (引数が既にそれだけインクリメント参照カウントでそれを返すnumpyのアレイである場合を除く)

乾杯、

ジャック

答えて

1

機能PyArray_FROM_OTFはnumpyの配列に変換します。 http://docs.scipy.org/doc/numpy/user/c-info.how-to-extend.html#converting-an-arbitrary-sequence-objectを参照してください。例えば

PyObject* definitely_numpy_array = PyArray_FROM_OTF(might_be_numpy_array, 
       NPY_DOUBLE, // you need to specify a type 
       0 // there's assorted flags you can add to describe the exact format you want which are described in the documentation 
       ) 

これは任意の数のディメンションで機能するため、厳密に1Dが必要な場合は小切手を追加する必要があります。また、numpyヘッダーを含める必要があります( "numpy/arrayobject.h")

関連する問題