重新编码丢失的数据 Numpy
我正在使用 matplotlib cvs2rec 函数读取人口普查数据 - 工作正常,给了我一个很好的 ndarray 。
但是有几列的所有值都是 dtype |04 的“none”。当我进入 Atpy“TypeError: object of NoneType has no len()”时,这会引发问题。类似“9999”或其他缺失的内容Mask 在这种情况下不起作用,因为我将真实数组传递给 ATPY 并且它不会转换 MASK 中的 Put 函数不适用于任何值。更改值的最佳方法(我认为)。我认为某种布尔数组是可行的方法,但我无法让它工作,
那么什么是更改无值和/或未初始化的 numpy 数组的好/快速方法。诸如“9999”或其他重新编码,
谢谢,
马修。
I am reading in census data using the matplotlib cvs2rec function - works fine gives me a nice ndarray.
But there are several columns where all the values are '"none"" with dtype |04. This is cuasing problems when I lode into Atpy "TypeError: object of NoneType has no len()". Something like '9999' or other missing would work for me. Mask is not going to work in this case because I am passing the real array to ATPY and it will not convert MASK. The Put function in numpy will not work with none values wich is the best way to change values(I think). I think some sort of boolean array is the way to go but I can't get it to work.
So what is a good/fast way to change none values and/or uninitialized numpy array to something like '9999'or other recode. No Masking.
Thanks,
Matthew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是此问题的解决方案,但如果您的数据是记录数组,您应该只将此操作应用于您的列,而不是整个数组:
请注意,您需要将
None
转换为 numpy 数组为了这个工作Here is a solution to this problem, although if your data is a record array you should only apply this operation to your column, rather than the whole array:
Note that you need to cast
None
into a numpy array for this to work计算时可以使用掩码数组。当将数组传递给ATPY时,可以调用掩码数组的filled(9999)方法将掩码数组转换为普通数组,并将无效值替换为9999。
you can use mask array when you do calculation. and when pass the array to ATPY, you can call filled(9999) method of the mask array to convert the mask array to normal array with invalid values replaced by 9999.