尝试将 matrix
通过 to_numpy()
导出,报错:
代码:
A[i].to_numpy()
错误:
AttributeError: module 'taichi.lang.matrix_ops' has no attribute 'to_numpy'
尝试将 matrix
通过 to_numpy()
导出,报错:
代码:
A[i].to_numpy()
错误:
AttributeError: module 'taichi.lang.matrix_ops' has no attribute 'to_numpy'
Hi, have you solved this issue?
No, I haven’t solved the issue yet.
我这里可以导出啊
import taichi as ti
import numpy as np
ti.init(arch = ti.cuda)
a = ti.Matrix.field(3,3,float, shape= 100)
@ti.kernel
def fill():
for i in ti.grouped(a):
a[i] = ti.Matrix([[1,0,0],[0,1,0],[0,0,1]])
fill()
b = a.to_numpy()
print(b)
c = a[5].to_numpy()
print(c)
结果是:
[Taichi] version 1.7.0, llvm 15.0.1, commit 2fd24490, win, python 3.11.5
[Taichi] Starting on arch=cuda
[[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
......
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
我i用的是taichi 1.7.0,可能是版本问题?
您的代码在Taichi 1.6和1.7都可以输出正确的结果,可能我的代码有一些问题,感谢回复!