- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 numba 在我的 GPU 上执行 np.diff。
这是我使用的脚本;
import numpy as np
import numba
@numba.vectorize(["float32(float32, float32)"], target='cuda')
def vector_diff_axis0(a, b):
return a + b
def my_diff(A, axis=0):
if (axis == 0):
return vector_diff_axis0(A[1:], A[:-1])
if (axis == 1):
return vector_diff_axis0(A[:,1:], A[:,:-1])
A = np.matrix([
[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9],
[9, 8, 7, 6, 5],
[4, 3, 2, 1, 0],
[0, 2, 4, 6, 8]
], dtype='float32')
C = my_diff(A, axis=1)
print (str(C))
这是我得到的错误;
TypeError: No matching version. GPU ufunc requires array arguments
to have the exact types. This behaves like regular ufunc with casting='no'.
有人知道这是什么原因吗?
PS:我用这个视频来做我的剧本; https://youtu.be/jKV1m8APttU?t=388
编辑:感谢您的快速回答!
我在 np.matrix 中添加了 dtype='float32' 但现在出现此错误; 已知签名: * (float32, float32) -> float32 文件“”,第 5 行 [1] 期间:解析被调用者类型:Function( 签名=(float32, float32) -> float32>) [2] 期间:在 (5) 处输入调用
我也尝试在签名中使用 float32[:] 但它不起作用,在我关注的视频中他们没有这样做
最佳答案
矩阵的 dtype 将是 int32
,这与 vector_diff_axis0
的签名不匹配,因为它需要 float32
。您需要制作矩阵 float32
,即在调用 np.matrix
时传递参数 dtype='float32'
。
关于python - Numba python3 出错 [GPU ufunc 要求数组参数具有准确的类型。],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44997860/
有没有办法判断一个 ndarray 子类的 __array_wrap__是用一元函数还是二元函数调用的? (另一个 reference ) 最佳答案 这只是部分答案: ufunc 的参数作为元组传递给
算术 numpy 表达式的内存消耗是多少 vec ** 3 + vec ** 2 + vec (vec 是 numpy.ndarray)。是否为每个中间操作存储一个数组?这样的复合表达式是否可以比底层
假设我有以下 numpy 数组: >>> a=np.zeros(10) >>> a array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
使用 numpy ndarray大多数时候我们不需要担心内存布局的问题,因为结果并不依赖于它。 除非他们这样做。例如,考虑这种设置 3x2 矩阵对角线的稍微过度设计的方法 >>> a = np.zer
我当然可以 a[a == 0] = something 将 a 中每个等于 0 的条目设置为 something。同样,我可以写 a[np.equal(a, 0)] = something 现在,想象
我当然可以 a[a == 0] = something 将 a 中每个等于 0 的条目设置为 something。同样,我可以写 a[np.equal(a, 0)] = something 现在,想象
有没有办法使用 numpy ufunc.at(特别是 add.at)来连接字符串数组? add.at 或 char.add.at 都不能用于字符串/字符数组。 该方法需要处理n维数组,所以先根据索引拆
我正在尝试使用 MPI 将模块广播到其他 python 进程。当然,模块本身不可 pickle ,但 __dict__ 可以。目前,我正在 pickle __dict__ 并在接收过程中制作一个新模块
有没有一个ufunc只转发数据? 在大多数情况下实现相同的效果并不困难,但有时在显式使用 ufunc 时,使用仅转发数据的函数会很方便。主要用于测试/调试并具有一致的代码外观。 例如,当我有一个接受
在我跟踪粒子路径的程序中,出现以下错误: Traceback (most recent call last): File "C:\Users\Felix\Google Drive\Research
我正在慢慢学习一些机器学习,但在一次使用计算机视觉对 kaggle 猫狗数据集进行练习时,发生了一些我不太明白的事情。 然后当我尝试规范化 pickle 中的图像值时,它在编写时起作用 X = X/2
我使用 Anaconda 和 gdsCAD,当所有软件包都正确安装时出现错误。就像这里解释的那样:http://pythonhosted.org/gdsCAD/ TypeError: ufunc 'a
基本上我有一个在 npy_cdouble 上运行的 numpy ufunc和npy_cfloat数组。例如: static void ufunc_H( char ** args , np
我想知道 r = ufct.identity 在函数 ufunc_reduce 中做了什么。它是否只是像 r = 0 一样初始化操作? a = np.array([2,3,4,5]) b = np.a
这个问题有关于使用输入作为输出来使用 numpy.ufunc 计算某些东西的信息: Numpy passing input array as `out` argument to ufunc 是否可以避
假设我们有一个接受 Numpy 数组并返回另一个数组的 Python 函数: import numpy as np def f(x, y, method='p'): """Parameters
我看到 Universal Function(ufunc) 用于执行按元素的数组操作。 arr = np.arange(5) arr2 = np.arange(5,10) np.add(arr,
我觉得 numpy.power 没有轴参数很奇怪……是因为有更好/更安全的方法来实现相同的目标(将 3D 数组中的每个 2D 数组提升为 1D 数组的幂) . 假设您有一个 (3,10,10) 数组
我有一个 numpy 数组,我想找到它的最大元素,所以我调用: x = foo.max() 问题是 foo 有时是一个空数组,max 函数(可以理解)抛出: ValueError: zero-size
我很好奇使用 numpy 的好处和权衡 ufuncs vs. 内置运算符 vs. 内置运算符的“函数”版本。 我对所有 ufunc 都很好奇。也许有些时候有些比其他更有用。但是,我将使用 >> x =
我是一名优秀的程序员,十分优秀!