Python 数据类型错误

Python 数据类型错误,python,types,numpy,python-imaging-library,Python,Types,Numpy,Python Imaging Library,当我运行此代码时,我会得到以下输出: TypeError: an integer is required 我不知道为什么会发生这种情况,因为我将这两种数据类型分别设置为uint8和uint64。显然,我不太了解数据类型 from PIL import Image from numpy import random N = 100 ##open an image im=Image.open('/Users/grahamwarner/Desktop/Experiment/gwarner/lab

当我运行此代码时,我会得到以下输出:

TypeError: an integer is required
我不知道为什么会发生这种情况,因为我将这两种数据类型分别设置为uint8和uint64。显然,我不太了解数据类型

from PIL import Image

from numpy import random

N = 100

##open an image
im=Image.open('/Users/grahamwarner/Desktop/Experiment/gwarner/labeled_photos/masks/003030.png')

##create a random image
rand_matrix = random.randint(0, 255, (500, 500, 3)).astype('uint8')

rand_image = Image.fromarray(rand_matrix)

##select N random pixels
rand_pix = random.randint(0,499, (N,2)).astype('uint64')

##replace the random values at these pixels with the original values
for ii in range(N):

  rand_image.putpixel(tuple(rand_pix[ii,:]), im.getpixel(tuple(rand_pix[ii,:])))

PIL中的
getpixel
方法似乎对其输入非常挑剔,特别需要
int
s的元组(这与Numpy的
uint64
类型不同)。以下是我的作品:

for ii in range(N):
    coordinate = tuple(map(int, rand_pix[ii,:]))
    rand_image.putpixel(coordinate, im.getpixel(coordinate))

PIL中的
getpixel
方法似乎对其输入非常挑剔,特别需要
int
s的元组(这与Numpy的
uint64
类型不同)。以下是我的作品:

for ii in range(N):
    coordinate = tuple(map(int, rand_pix[ii,:]))
    rand_image.putpixel(coordinate, im.getpixel(coordinate))

出现了哪一行?如果此问题的答案令您满意,您应该接受最佳答案,请参阅。出现了哪一行?如果此问题的答案令您满意,您应该接受最佳答案,请参阅。