2016-07-13 60 views
2

當我運行:IndexError:指數43770是出界對軸0,大小37550

im = np.zeros((37550, 59759)) 

location = [(23913, 43770), (23914, 43731), (23914, 43734), (23916, 43734), 
      (23916, 43740), (23917, 43740), (23917, 43742), (23918, 43743), 
      (23918, 43745), (23919, 43746), (23919, 43748), (23920, 43750), 
      (23920, 43763), (23919, 43764), (23919, 43765), (23918, 43766), 
      (23918, 43768), (23917, 43769), (23917, 43770), (23916, 43771), 
      (23916, 43773), (23914, 43775), (23913, 43779), (23910, 43782), 
      (23909, 43784), (23909, 43786), (23906, 43792), (23906, 43795), 
      (23903, 43796), (23902, 43799), (23899, 43802), (23898, 43804), 
      (23897, 43805), (23896, 43808), (23892, 43810), (23891, 43813), 
      (23889, 43814), (23874, 43814), (23874, 43812), (23873, 43811), 
      (23873, 43809), (23872, 43808), (23870, 43802), (23869, 43801), 
      (23867, 43796), (23864, 43791), (23864, 43789), (23862, 43784), 
      (23861, 43783), (23860, 43781), (23857, 43780), (23856, 43779), 
      (23838, 43779), (23837, 43780), (23834, 43780), (23832, 43781), 
      (23830, 43783), (23828, 43783), (23827, 43785), (23823, 43789), 
      (23821, 43790), (23820, 43790), (23816, 43794), (23812, 43796), 
      (23810, 43798), (23806, 43800), (23802, 43801), (23797, 43801), 
      (23797, 43800), (23796, 43800), (23796, 43799), (23793, 43798), 
      (23793, 43796), (23791, 43794), (23791, 43764), (23792, 43762), 
      (23792, 43759), (23793, 43758), (23793, 43756), (23794, 43754), 
      (23794, 43753), (23796, 43752), (23797, 43751), (23800, 43745), 
      (23800, 43744), (23803, 43741), (23804, 43739), (23806, 43738), 
      (23807, 43735), (23808, 43733), (23810, 43731), (23811, 43728), 
      (23813, 43724), (23816, 43721), (23819, 43715), (23820, 43712), 
      (23822, 43709), (23823, 43705), (23828, 43700), (23830, 43696), 
      (23837, 43686), (23839, 43682), (23846, 43675), (23848, 43670), 
      (23851, 43666), (23853, 43662), (23856, 43659), (23860, 43654), 
      (23862, 43650), (23866, 43648), (23871, 43640), (23874, 43634), 
      (23877, 43632), (23878, 43630), (23880, 43628), (23881, 43625), 
      (23883, 43621), (23889, 43618), (23890, 43616), (23892, 43614), 
      (23903, 43614), (23907, 43615), (23908, 43616), (23909, 43618), 
      (23911, 43618), (23911, 43619), (23912, 43619), (23912, 43620), 
      (23913, 43621), (23913, 43623), (23914, 43625), (23914, 43626), 
      (23917, 43632), (23917, 43688), (23916, 43689), (23916, 43693), 
      (23914, 43695), (23914, 43698), (23913, 43700), (23913, 43770)] 

im[location] = 4 

我得到以下回溯:

IndexError        Traceback (most recent call last) 
<ipython-input-6-2fb0def4341d> in <module>() 
----> 1 arr[location] = 4 

IndexError: index 43770 is out of bounds for axis 0 with size 37550 

爲什麼不這項工作,爲什麼它是否認爲(23913,43770)中的43770應該沿着軸線0?我試過扭轉元組,並得到相同的錯誤。我錯過了明顯的東西嗎?

回答

2

而不是(x, y)對(即[(x1, y1), (x2, y2), ...]),您需要通過類似[(x1, x2, ...), (y1, y2, ...)]。這也不是我期待的(見類似問題here)。 @hpaulj's suggestion是使用zip。對於您的問題:

im[tuple(zip(*location))] = 4 

給出您正在尋找的結果。

+0

這工作,謝謝! –

相關問題