masked-array

Create mask from skimage contour

ぃ、小莉子 提交于 2021-02-18 14:56:52
问题 I have an image that I found contours on with skimage.measure.find_contours() but now I want to create a mask for the pixels fully outside the largest closed contour. Any idea how to do this? Modifying the example in the documentation: import numpy as np import matplotlib.pyplot as plt from skimage import measure # Construct some test data x, y = np.ogrid[-np.pi:np.pi:100j, -np.pi:np.pi:100j] r = np.sin(np.exp((np.sin(x)**2 + np.cos(y)**2))) # Find contours at a constant value of 0.8 contours

Create mask from skimage contour

被刻印的时光 ゝ 提交于 2021-02-18 14:56:44
问题 I have an image that I found contours on with skimage.measure.find_contours() but now I want to create a mask for the pixels fully outside the largest closed contour. Any idea how to do this? Modifying the example in the documentation: import numpy as np import matplotlib.pyplot as plt from skimage import measure # Construct some test data x, y = np.ogrid[-np.pi:np.pi:100j, -np.pi:np.pi:100j] r = np.sin(np.exp((np.sin(x)**2 + np.cos(y)**2))) # Find contours at a constant value of 0.8 contours

Create mask from skimage contour

有些话、适合烂在心里 提交于 2021-02-18 14:54:48
问题 I have an image that I found contours on with skimage.measure.find_contours() but now I want to create a mask for the pixels fully outside the largest closed contour. Any idea how to do this? Modifying the example in the documentation: import numpy as np import matplotlib.pyplot as plt from skimage import measure # Construct some test data x, y = np.ogrid[-np.pi:np.pi:100j, -np.pi:np.pi:100j] r = np.sin(np.exp((np.sin(x)**2 + np.cos(y)**2))) # Find contours at a constant value of 0.8 contours

Create mask from skimage contour

被刻印的时光 ゝ 提交于 2021-02-18 14:54:47
问题 I have an image that I found contours on with skimage.measure.find_contours() but now I want to create a mask for the pixels fully outside the largest closed contour. Any idea how to do this? Modifying the example in the documentation: import numpy as np import matplotlib.pyplot as plt from skimage import measure # Construct some test data x, y = np.ogrid[-np.pi:np.pi:100j, -np.pi:np.pi:100j] r = np.sin(np.exp((np.sin(x)**2 + np.cos(y)**2))) # Find contours at a constant value of 0.8 contours

numpy genfromtxt - missing data vs bad data

跟風遠走 提交于 2021-01-07 06:31:10
问题 I'm using numpy genfromtxt, and I need to identify both missing data and bad data. Depending on user input, I may want to drop bad value or raise error. Essentially, I want to treat missing and bad data as the same thing. Say I have a file like this, where the columns are of data types "date, int, float" date,id,value 2017-12-4,0, # BAD. missing data 2017-12-4,1,XYZ # BAD. value should be float, not string. 2017-12-4,2,1.0 # good 2017-12-4,3,1.0 # good 2017-12-4,4,1.0 # good I would like to

Why are Numpy masked arrays useful?

余生长醉 提交于 2020-07-18 05:59:48
问题 I've been reading through the masked array documentation and I'm confused - what is different about MaskedArray than just maintaining an array of values and a boolean mask? Can someone give me an example where MaskedArrays are way more convenient, or higher performing? Update 6/5 To be more concrete about my question, here is the classic example of how one uses a MaskedArray: >>>data = np.arange(12).reshape(3, 4) >>>mask = np.array([[0., 0., 1., 0.], [0., 0., 0., 1.], [0., 1., 0., 0.]]) >>

How can I change the value of a masked array in numpy?

寵の児 提交于 2020-01-30 05:02:10
问题 In my code, at some point I try to modify a value of a masked array, yet python seems to ignore this. I'm thinking this has to do with the way memory is stored in arrays, as if I were modifying a copy of the value and not the value itself, but I'm not well versed enough in this to have any clue how to resolve it. Here is a simplified version of what I'm trying to do : x = np.zeros((2,5)) # create 2D array of zeroes x[0][1:3] = 5 # replace some values along 1st dimension with 5 mask = (x[0] >

numpy.ma (masked) array mean method has inconsitent return type

自闭症网瘾萝莉.ら 提交于 2019-12-29 08:41:26
问题 I noticed that the numpy masked-array mean method returns different types when it probably should not: import numpy as np A = np.ma.masked_equal([1,1,0], value=0) B = np.ma.masked_equal([1,1,1], value=0) # no masked values type(A.mean()) #numpy.float64 type(B.mean()) #numpy.ma.core.MaskedArray Other numpy.ma.core.MaskedArray methods seem to be consistent type( A.sum()) == type(B.sum()) # True type( A.prod()) == type(B.prod()) # True type( A.std()) == type(B.std()) # True type( A.mean()) ==

Calculate moving average in numpy array with NaNs

牧云@^-^@ 提交于 2019-12-08 02:32:10
问题 I am trying to calculate the moving average in a large numpy array that contains NaNs. Currently I am using: import numpy as np def moving_average(a,n=5): ret = np.cumsum(a,dtype=float) ret[n:] = ret[n:]-ret[:-n] return ret[-1:]/n When calculating with a masked array: x = np.array([1.,3,np.nan,7,8,1,2,4,np.nan,np.nan,4,4,np.nan,1,3,6,3]) mx = np.ma.masked_array(x,np.isnan(x)) y = moving_average(mx).filled(np.nan) print y >>> array([3.8,3.8,3.6,nan,nan,nan,2,2.4,nan,nan,nan,2.8,2.6]) The

How can I mask elements of a record array in Numpy?

倖福魔咒の 提交于 2019-12-07 02:01:10
问题 I understand how to create a masked array, and I would like to use masking in a record array so that I can access this data using named attributes. The masking seems to be "lost" when I create a record array from a masked array: >>> data = np.ma.array(np.ma.zeros(30, dtype=[('date', '|O4'), ('price', '<f8')]),mask=[i<10 for i in range(30)]) >>> data masked_array(data = [(--, --) (--, --) (--, --) (--, --) (--, --) (--, --) (--, --) (--, --) (--, --) (--, --) (0, 0.0) (0, 0.0) (0, 0.0) (0, 0.0