我已经看到这个问题被问到,但还没有真正找到完整的答复。我有一个简单的形状多边形,称为polygon。我想提取这个多边形作为二进制掩码(最好是 numpy 数组)。我该怎么做呢?
我还设法从 shapely 转换为 geopandas,如此处所示,因此从 geopandas 中提取掩模也可以工作,但不幸的是,我还没有真正找到这方面的线索。
编辑:要清楚,如果我要使用坐标网格,我的网格包含与构成形状轮廓的点相对应的 x 和 y 笛卡尔坐标(无序)。这些是浮点数,因此需要 int 输入的解决方案不太有效。理想情况下,我希望起点是一个匀称的多边形而不是一组点,但如果这是更可取的,我可以使用一组无序的点(或者以某种方式从匀称的多边形中提取顺时针顶点)
我已经尝试过 Yusuke 的方法,但我得到的面具不太有意义。
佑介的方法:
#%% create grid and plot
nx, ny = 100, 100
poly_verts = Plane1verts #this is a list of tuples containing cartesian coordinate pairs of the shape contour in x and y
# Create vertex coordinates for each grid cell...
# (<0,0> is at the top left of the grid in this system)
x, y …Run Code Online (Sandbox Code Playgroud) 我试图在 pandas 数据框中删除方差为 0 的列。我确信这个问题已经在某个地方得到了回答,但我在找到相关线索时遇到了很多麻烦。我找到了这个线程baseline,但是当我使用命令尝试数据框的解决方案时
baseline_filtered=baseline.loc[:,baseline.std() > 0.0]
Run Code Online (Sandbox Code Playgroud)
我收到错误
"Unalignable boolean Series provided as "
IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match).
Run Code Online (Sandbox Code Playgroud)
那么,有人可以告诉我为什么会收到此错误或提供替代解决方案吗?