首页 > 解决方案 > 打印 Cython Memoryview

问题描述

我是 Cython 的新手,并创建了一些名为evaluate_c. 在这个阶段我要做的就是打印到 temp_info 的前 5 个元素,它是浮点数组 - 只是为了观察数据。

cpdef void evaluate_c(TempLogicPy engine,
    double [:] temp_info):
    print(temp_info[:5])

temp_info 具有以下类型:

('temp_info type: ', <class 'project.temp_test._memoryviewslice'>)

我试过使用print(temp_info[:5])它不会返回任何浮点数。

标签: pythoncython

解决方案


您可以将其转换为另一种(可打印)类型:

 print(list(temp_info[:5]))

或者你对元素进行交互:

 for i in range(temp_info.shape[0]):
      print(temp_info[i], end=" ")
 print()  # newline

推荐阅读