当被索引数组a是多维的时,每一个唯一的索引数列指向a的第一维 5 。以下示例通过将图片标签用调色版转换成色彩图像展示了这种行为。
>>> palette = array( [ [0,0,0], # black
... [255,0,0], # red
... [0,255,0], # green
... [0,0,255], # blue
... [255,255,255] ] ) # white
>>> image = array( [ [ 0, 1, 2, 0 ], # each value corresponds to a color in the palette
... [ 0, 3, 4, 0 ] ] )
>>> palette[image] # the (2,4,3) color image
array([[[ 0, 0, 0],
[255, 0, 0],
[ 0, 255, 0],
[ 0, 0, 0]],
[[ 0, 0, 0],
[ 0, 0, 255],
[255, 255, 255],
[ 0, 0, 0]]])
>>> palette = array( [ [0,0,0], # black
... [255,0,0], # red
... [0,255,0], # green
... [0,0,255], # blue
... [255,255,255] ] ) # white
>>> image = array( [ [ 0, 1, 2, 0 ], # each value corresponds to a col
or in the palette
... [ 0, 3, 4, 0 ] ] )
>>> image
array([[0, 1, 2, 0],
[0, 3, 4, 0]])
>>> image.shape
(2, 4)
>>> palette.shape
(5, 3)
>>> pimg=palette[image]
>>> pimg.shape
(2, 4, 3)
>>> pimg
array([[[ 0, 0, 0],
[255, 0, 0],
[ 0, 255, 0],
[ 0, 0, 0]],
[[ 0, 0, 0],
[ 0, 0, 255],
[255, 255, 255],
[ 0, 0, 0]]])
>>>
图片格式 jpg、png、gif各有什么优缺点?什么情况下用什么格式的图片呢?