파이썬 목록을 반복하는 cython 함수에 보내면 목록 항목이 어떤 유형인지 선언해야할까요? 또한 cython으로 목록을 반복하는 가장 좋은 방법은 무엇입니까? 예 :항목 유형을 cython에서 정의해야합니까?
#Cython function, passed a list of float items
def cython_f(list example_list):
cdef int i
for i in range(len(example_list)):
#Do stuff
#but list item type not defined?
pass
#Alternative loop
cdef j float #declaration of list item type
for j in example_list:
#Do stuff
pass
* 편집 : 목록 항목 유형을 정의 할 때 속도가 향상 되었습니까? 파이썬리스트 대신 numpy 배열을 전달하는 것이 더 좋습니까? 많은 질문에 사과드립니다.
감사합니다. 훌륭한 답변입니다. – kezzos
'libcpp.vector' 대신'cpython.array' (http://stackoverflow.com/questions/18462785/what-is-the-commended-way를 참고하십시오)라는 몇 가지 좋은 대안이 있습니다. -of-allocating-memory-for-a-typed-memory-view)에 대한 정보를 제공합니다. 최선의 선택은 분명히 상황에 달려 있습니다. – Veedrac