打印 Cython 内存视图

Print a Cython Memoryview

我是 Cython 的新手,创建了一些名为 evaluate_c 的 Cython 代码。在这个阶段我要做的就是打印到 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]) 它没有 return 任何浮动。

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

 print(list(temp_info[:5]))

或者你对元素进行交互:

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