为什么当我检查我的数组维度时,它会说[3L,3L]
?为什么不只是[3,3]
?这会影响我访问数组中元素的能力,因为我传递的是一个不是整数的浮点数。
请参阅下面的示例:
kernel_x = [
[ -1, 0, 1 ],
[ -2, 0, 2 ],
[ -1, 0, 1 ]
]
kernel_x_mat = np.array(kernel_x)
dim = kernel_x_mat.shape
print dim # [3L,3L]
# The long causes an error because I get
# floats from ::shape
# Ie, this is invalid...
src[r,c] = kernel_x_mat[dim[0]-1, dim[1]-1]
# dim[0]-1 = 2.0 not 2 which causes an error