python - 打印 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])
它不会返回任何浮点数。
解决方案
您可以将其转换为另一种(可打印)类型:
print(list(temp_info[:5]))
或者你对元素进行交互:
for i in range(temp_info.shape[0]):
print(temp_info[i], end=" ")
print() # newline
推荐阅读
- java - 将 Spring Boot 应用程序推送到 Heroku 未完成
- javascript - javascript函数在require语句后什么时候需要空括号?
- javascript - jquery.trim() 是否已弃用?
- unity3d - 如何让玩家可以访问资产进行改装?
- sql - 如何根据sql中的某些条件连接两个表?
- java - 如何为 netbeans java 添加 jxbrowser 的许可证密钥?
- graph - Gremlin 查询输出到 CSV 文件
- python - 使用 pandas 的泊松过程的 KeyError
- android - 在 Android 中实现语言选择器
- c# - 如何确保从抽象泛型类派生的类将自身用作泛型参数