【发布时间】:2013-05-26 14:56:52
【问题描述】:
如果你有以下代码:
import numpy as np
def myFunction(element, index):
print element, index
myVector = np.vectorize(myFunction)
myVector(myArray, currentElementIndex)
- 如何在 Numpy 向量化中将
currentElementIndex值传递给myFunction()?
提前致谢!
编辑:我不太确定应该在哪里获取应用myFunction() 的当前项目的索引。我知道如何传递数组元素,但不知道索引。
编辑:用实际代码更新:
import numpy as npy
def getHashValue(character, index):
return (ord(character) - ord('a')) ** (index + 1)
def getNameHash(name):
hashValue = getHashValue
hashValue = npy.vectorize(hashValue)
hashValue(shortName)
return
【问题讨论】:
-
你真正想做什么?问题出在哪里? (我不太明白你的问题)
-
好吧,我不确定我应该在哪里获得应用“myFunction()”的当前项目的索引。我知道如何传递数组元素,但不知道索引。
-
您能告诉我们您正在做什么(一个最小的工作示例)以及您希望发生什么吗?您的代码如何不给您应用
myFunction的项目?这正是它要打印的内容。 -
我用我的代码更新了我的问题。我想将“getHashValue()”应用于“shortName”字符串中的每个字符。这里的问题是这个函数还需要字符串中每个字符的索引/位置。
标签: arrays numpy vectorization