np arrays being immutable - “assignment destination is read-only”

前端 未结 4 2123
礼貌的吻别
礼貌的吻别 2020-11-30 04:30

FD** - I am a Python newb as well as a stack overflow newb as you can tell. I have edited the question based on comments.

My goal is to read a set of PNG files, crea

4条回答
  •  旧时难觅i
    2020-11-30 04:59

    In this case, I think you are trying to edit the image provided to you by another user and he/she made it uneditable that's why you are getting this error. For your case, you may try to make a copy of the given file and do changes on that file by using .copy().

         img_copy = img.copy()
         prArray = [np.asarray(img_copy)[:, :, 0] for img_copy in problem_images]
    

    And more importantly, I do not think that most of us want to make changes to our original image, that's why I always use .copy() and recommend you to do the same.

提交回复
热议问题