0
파이썬에서 데이터 분석 (예 : 로컬 바이너리 패턴 사용)을하고 코드를 최적화하려고합니다. 내 코드에서는 현재 numpu ndarray
벡터로 구현 된 이진 벡터를 사용하고 있습니다. 다음은 내 코드의 세 가지 기능입니다.효율적으로 파이썬에서 바이너리 벡터를 표현하는 방법
# Will return a binary vector presentation of the neighbourhood
#
# INPUTS:
# 'ndata' numpy ndarray consisting of the neighbourhood X- and Y- coordinates and values
# 'thres' decimal value indicating the value of the center pixel
#
# OUTPUT:
# 'bvec' binary vector presentation of the neighbourhood
def toBinvec(ndata, thres):
bvec = np.zeros((len(ndata), 1))
for i in range(0, len(ndata)):
if ndata[i, 2]-thres < 0:
bvec[i] = 0
else:
bvec[i] = 1
return bvec
# Will check whether a given binary vector is uniform or not
# A binary pattern is uniform if when rotated one step, the number of
# bit values changing is <= 2
#
# INPUTS:
# 'binvec' is a binary vector of type numpy ndarray
#
# OUTPUT:
# 'True/False' boolean indicating uniformness
def isUniform(binvec):
temp = rotateDown(binvec) # This will rotate the binary vector one step down
devi = 0
for i in range(0, len(temp)):
if temp[i] != binvec[i]:
devi += 1
if devi > 2:
return False
else:
return True
# Will return the corresponding decimal number of binary vector
#
# INPUTS:
# 'binvec' is a binary vector of type numpy ndarray
#
# OUTPUT:
# 'value' The evaluated decimal value of the binary vector
def evaluate(binvec):
value = 0
for i in range(0, len(binvec)):
value += binvec[i]*(2**i)
return value
코드를보다 효율적으로 만들기 위해 내 바이너리 벡터를 구현해야하는 다른 방법이 있습니까? 이 코드는 빅 데이터 분석과 함께 사용되므로 효율성은 중요한 문제입니다.
또한 이진 벡터에 몇 가지 조작을해야합니다. 회전하여 십진법 값 등을 평가합니다.
도움/도움이되어 주셔서 감사합니다! =)
+1 감사합니다. =) – jjepsuomi