python字符串数组切片性能_python – 为数组切片赋值很慢

我正在尝试通过在Cython中实现它来优化Python算法.我的问题是关于以下代码中存在的某个性能瓶颈:@cython.boundscheck(False) # turn off bounds-checking for entire functiondef anglesToRGB( np.ndarray[double, ndim=2] y, np.ndarray[double, ndim=2] x...
摘要由CSDN通过智能技术生成

我正在尝试通过在Cython中实现它来优化

Python算法.我的问题是关于以下代码中存在的某个性能瓶颈:

@cython.boundscheck(False) # turn off bounds-checking for entire function

def anglesToRGB( np.ndarray[double, ndim=2] y, np.ndarray[double, ndim=2] x ):

cdef double angle

cdef double Hp

cdef double C

cdef double X

cdef np.ndarray[double, ndim=3] res = np.zeros([y.shape[0], y.shape[1], 3], dtype=np.float64)

for i in xrange(y.shape[0]):

for j in xrange(y.shape[1]):

angle = atan2( y[i,j], x[i,j] )*180.0/PI+180

C = sqrt(pow(y[i,j],2)+pow(x[i,j],2))/360.0 #Chroma

Hp = angle/60.0

X = C*(1-fabs( Hp%2-1))

C *= 255

X *= 255

if (0. <= Hp < 1.):

res[i,j,:] = [C,X,0]

elif (1. <= Hp < 2.):

res[i,j,:] = [X,C,0]

elif (2. <= Hp <

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值