mask

Pandas best way to subset a dataframe inplace, using a mask

青春壹個敷衍的年華 提交于 2019-12-06 02:02:07
问题 I have a pandas dataset that I want to downsize (remove all values under x). The mask is df[my_column] > 50 I would typically just use df = df[mask] , but want to avoid making a copy every time, particularly because it gets error prone when used in functions (as it only gets altered in the function scope). What is the best way to subset a dataset inplace? I was thinking of something along the lines of df.drop(df.loc[mask].index, inplace = True) Is there a better way to do this, or any

boolean mask in pandas panel

空扰寡人 提交于 2019-12-06 01:30:59
问题 i am having some trouble masking a panel in the same way that I would a DataFrame. What I want to do feels simple, but I have not found a way looking at the docs and online forums. I have a simple example below: import pandas import numpy as np import datetime start_date = datetime.datetime(2009,3,1,6,29,59) r = pandas.date_range(start_date, periods=12) cols_1 = ['AAPL', 'AAPL', 'GOOG', 'GOOG', 'GS', 'GS'] cols_2 = ['close', 'rate', 'close', 'rate', 'close', 'rate'] dat = np.random.randn(12,

Fill oceans in basemap [duplicate]

牧云@^-^@ 提交于 2019-12-05 22:22:46
This question already has an answer here: Plot only on continent in matplotlib 5 answers I am trying to plot 1x1 degree data on a matplotlib.Basemap , and I want to fill the ocean with white. However, in order for the boundaries of the ocean to follow the coastlines drawn by matplotlib , the resolution of the white ocean mask should be much higher than the resolution of my data. After searching around for a long time I tried the two possible solutions: (1) maskoceans() and is_land() functions, but since my data is lower resolution than the map drawn by basemap it does not look good on the

PHP - Mask polygon over image

馋奶兔 提交于 2019-12-05 18:53:32
Hi Everyone (this is my first post), I am trying to figure a way of cropping a polygon out of an image. I have been reading other similar code. It seems that most code is based around the following process: Resize the image to fit the width and height of the polygon shape, Create a blank image of an unusual colour the same size, Overlay transparent pixels in the shape of the polygon, Overlay that on to the resized image Set the unusual colour to be transparent... My problem is I do not want the code to be reliant on the unusual colour not being in the original image. Does anyone have a better

Animate circular mask of UIImageView in iOS

拜拜、爱过 提交于 2019-12-05 16:26:44
问题 I am wondering how to animate the scale of a mask on a uiimageview. Example images attached. The gray boxes are the image background of my uiviewcontroller and is not part of the issue. I assume creation of a uiview subclass that I pass an image, a radius and a center point. And then (?) create a mask, and then animate it back and forth? Can anyone point me in the right direction? The circle can be placed anywhere, at any size, but the image to be revealed is always full screen. Eventually I

How to mask out a simple region when painting in Android?

北城余情 提交于 2019-12-05 16:07:01
Here is a simplified description: Imagine that I'm given a View class that draws a picture of a wall and I want to draw it with a window cut out. Assume that I extend that View class and override its dispatchDraw() method to do the following. First draw the background if any to be seen through the window. Next I want to mask out the rectangular window region somehow and then call super.dispatchDraw(). Finally I want to remove the mask and draw a person standing at the window so that they are painted over both the background and the wall. How can I do this? Here is some code that seems close to

Create mask by first positions only

旧城冷巷雨未停 提交于 2019-12-05 11:04:19
I have array: a = np.array([[ 0, 1, 2, 0, 0, 0], [ 0, 4, 1, 35, 0, 10], [ 0, 0, 5, 4, 0, 4], [ 1, 2, 5, 4, 0, 4]]) I need select only from first consecutive 0 in each row: [[ True False False False False False] [ True False False False False False] [ True True False False False False] [ False False False False False False]] I try: a[np.arange(len(a)), a.argmax(1): np.arange(len(a)), [0,0,0]] = True But this is wrong. You can use np.cumsum . Assumption: you are looking for zeros only at the start of each row. a = np.array([[ 0, 1, 2, 0, 0, 0], [ 0, 4, 1, 35, 0, 10], [ 0, 0, 5, 4, 0, 4]]) a

CGPath from image

天涯浪子 提交于 2019-12-05 08:01:01
问题 I need to create mask based on image (any possible shape). I need to: Create CALayer with CGPath as a proper mask Call [UIView.layer setMask: with layer above ] So main big question is how to set CGPath based on black-white image? Or is it possible to place mask directly from image? Thanks! Example image of a mask: 回答1: You will need to create your image with an alpha channel. According to CALayer 's mask property documentation: An optional layer whose alpha channel is used as a mask to

Using an UIView as a Mask in another UIView on Swift

て烟熏妆下的殇ゞ 提交于 2019-12-05 05:28:24
I am developing an App on xCode with Swift. My screen has an Image of an animal (outlet "backImage"), over this image I have a view (outlet "coverView"), color black, which covers all the screen. So so far you can't see the animal image, because the "coverView" is in front of it. Then I have another view (outlet "maskView") which is smaller and it's over the big view "coverView". What I want is to use this "maskView" as mask and therefor see the "backImage" through it, like a window. Is there anyone out there able to figure this out? Here is my screen, I want to see the woman character behind

Mask a 3d array with a 2d mask in numpy

我们两清 提交于 2019-12-05 03:03:15
I have a 3-dimensional array that I want to mask using a 2-dimensional array that has the same dimensions as the two rightmost of the 3-dimensional array. Is there a way to do this without writing the following loop? import numpy as np nx = 2 nt = 4 field3d = np.random.rand(nt, nx, nx) field2d = np.random.rand(nx, nx) field3d_mask = np.zeros(field3d.shape, dtype=bool) for t in range(nt): field3d_mask[t,:,:] = field2d > 0.3 field3d = np.ma.array(field3d, mask=field3d_mask) print field2d print field3d Without the loop you could write it as: field3d_mask[:,:,:] = field2d[np.newaxis,:,:] > 0.3 For