Filling numpy array using [:,:] crashes python?

十年热恋 提交于 2019-12-23 04:15:26

问题


Greetings,

I have come across an interesting error and was wondering if anyone knew the cause.

I create several numpy arrays of dtype object and wish to initialize them with empty strings, so I did the following to create them:

txtInputs=empty((7,12), dtype=object)
txtInputs[:, :]=''

repeated...

How they are used after is not relevant other than that these variables are local to the function and are gone when it returns. However, I have discovered that when I call the function that does this many times in a row, my program crashes with an error saying pythonw.exe has stopped working. This crash is consistent and happens after a specific number of calls, and that number never changes.

However, if I replace the second line with:

txtInputs.fill('')

It will not crash. What is wrong with using [:,:]='' to fill the numpy array??

Thank you.

PS. I am using python 2.5 and numpy 1.0.4


回答1:


This error does not occur with numpy 1.5.1. We were fixing quite a few bugs around the time of numpy 1.0.4, particularly with the object and string dtypes. This is probably one of them. The bug has apparently been fixed since then.



来源:https://stackoverflow.com/questions/5340739/filling-numpy-array-using-crashes-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!