{"action":"created","issue":{"url":"https://api.github.com/repos/numpy/numpy/issues/3762","repository_url":"https://api.github.com/repos/numpy/numpy","labels_url":"https://api.github.com/repos/numpy/numpy/issues/3762/labels{/name}","comments_url":"https://api.github.com/repos/numpy/numpy/issues/3762/comments","events_url":"https://api.github.com/repos/numpy/numpy/issues/3762/events","html_url":"https://github.com/numpy/numpy/issues/3762","id":19720508,"number":3762,"title":"Operation on masked_array changes fill_value","user":{"login":"agartland","id":3869734,"avatar_url":"https://avatars.githubusercontent.com/u/3869734?v=3","gravatar_id":"","url":"https://api.github.com/users/agartland","html_url":"https://github.com/agartland","followers_url":"https://api.github.com/users/agartland/followers","following_url":"https://api.github.com/users/agartland/following{/other_user}","gists_url":"https://api.github.com/users/agartland/gists{/gist_id}","starred_url":"https://api.github.com/users/agartland/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agartland/subscriptions","organizations_url":"https://api.github.com/users/agartland/orgs","repos_url":"https://api.github.com/users/agartland/repos","events_url":"https://api.github.com/users/agartland/events{/privacy}","received_events_url":"https://api.github.com/users/agartland/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/numpy/numpy/labels/component:%20numpy.ma","name":"component: numpy.ma","color":"ff0000"},{"url":"https://api.github.com/repos/numpy/numpy/labels/Needs%20decision","name":"Needs decision","color":"207de5"},{"url":"https://api.github.com/repos/numpy/numpy/labels/priority:%20normal","name":"priority: normal","color":"ff0000"},{"url":"https://api.github.com/repos/numpy/numpy/labels/Proposal","name":"Proposal","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2013-09-19T00:13:20Z","updated_at":"2016-02-10T23:30:18Z","closed_at":null,"body":"I first raised this issue on stackoverflow (see link on the bottom)\r\n\r\nSeems like the new masked_array should inherit the fill_value from the two masked_arrays being summed?\r\n\r\nCan someone explain to me this behavior of a numpy masked_array? It seems to change the fill_value after applying the sum operation, which is confusing if you intend to use the filled result.\r\n\r\n    data=ones((5,5))\r\n    m=zeros((5,5),dtype=bool)\r\n \r\n    \"\"\"Mask out row 3\"\"\"\r\n    m[3,:]=True\r\n    arr=ma.masked_array(data,mask=m,fill_value=nan)\r\n\r\n    print arr\r\n    print 'Fill value:', arr.fill_value\r\n    print arr.filled()\r\n\r\n    farr=arr.sum(axis=1)\r\n    print farr\r\n    print 'Fill value:', farr.fill_value\r\n    print farr.filled()\r\n\r\n    \"\"\"I was expecting this\"\"\"\r\n    print nansum(arr.filled(),axis=1)\r\nPrints output:\r\n\r\n    [[1.0 1.0 1.0 1.0 1.0]\r\n     [1.0 1.0 1.0 1.0 1.0]\r\n     [1.0 1.0 1.0 1.0 1.0]\r\n     [-- -- -- -- --]\r\n     [1.0 1.0 1.0 1.0 1.0]]\r\n    Fill value: nan\r\n    [[  1.   1.   1.   1.   1.]\r\n     [  1.   1.   1.   1.   1.]\r\n     [  1.   1.   1.   1.   1.]\r\n     [ nan  nan  nan  nan  nan]\r\n     [  1.   1.   1.   1.   1.]]\r\n    [5.0 5.0 5.0 -- 5.0]\r\n    Fill value: 1e+20\r\n    [  5.00000000e+00   5.00000000e+00   5.00000000e+00   1.00000000e+20\r\n       5.00000000e+00]\r\n    [  5.   5.   5.  nan   5.]\r\n\r\n\r\nhttp://stackoverflow.com/questions/18879272/why-does-sum-operation-on-numpy-masked-array-change-fill-value-to-1e20"},"comment":{"url":"https://api.github.com/repos/numpy/numpy/issues/comments/182634422","html_url":"https://github.com/numpy/numpy/issues/3762#issuecomment-182634422","issue_url":"https://api.github.com/repos/numpy/numpy/issues/3762","id":182634422,"user":{"login":"alimuldal","id":2284074,"avatar_url":"https://avatars.githubusercontent.com/u/2284074?v=3","gravatar_id":"","url":"https://api.github.com/users/alimuldal","html_url":"https://github.com/alimuldal","followers_url":"https://api.github.com/users/alimuldal/followers","following_url":"https://api.github.com/users/alimuldal/following{/other_user}","gists_url":"https://api.github.com/users/alimuldal/gists{/gist_id}","starred_url":"https://api.github.com/users/alimuldal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alimuldal/subscriptions","organizations_url":"https://api.github.com/users/alimuldal/orgs","repos_url":"https://api.github.com/users/alimuldal/repos","events_url":"https://api.github.com/users/alimuldal/events{/privacy}","received_events_url":"https://api.github.com/users/alimuldal/received_events","type":"User","site_admin":false},"created_at":"2016-02-10T23:30:18Z","updated_at":"2016-02-10T23:30:18Z","body":"A related question popped up on SO today: http://stackoverflow.com/q/35324836/1461210\r\n\r\nIn versions >= 1.10.0:\r\n```python\r\nx = np.random.randn(10, 10)\r\nm = np.ma.masked_array(x, x < 0.5, fill_value=1)\r\nprint((m * m).fill_value)\r\n# 1e+20\r\n```\r\nPrior to 1.10.0 I get a fill value of 1.0, which seems more reasonable to me.\r\n\r\nThe behaviour in question seems to have been introduced in 3c6b6baba587297633b8744a3b2ade8644ad8a5e"}}