如何在python中合并来自两个矩形的网格网格点?

编程入门 行业动态 更新时间:2024-10-23 15:31:20
本文介绍了如何在python中合并来自两个矩形的网格网格点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要合并在两个不同(相邻)矩形处形成的网格.以下是矩形的图形表示:

I need to merge the mesh grids formed at two different (adjoining) rectangles. Following is the pictorial representation of the rectangle:

我可以创建各个矩形的网格.例如,对于绿色矩形,使用下面的代码片段,我们可以创建一个网格.

I can create the mesh grids of the individual rectangles. For example for the green rectangle, using following code snippet, we can create a mesh grid.

xvalues = np.array([0, 2, 4, 6, 8, 10]) yvalues = np.array([6, 8, 10, 12]) x, y = np.meshgrid(xvalues, yvalues) positions = np.vstack([x.ravel(), y.ravel()]) theGridPoints = (np.array(positions)).T

我也可以为蓝色矩形设置网格点.但是,我无法将它们加入单个对象内.我试图将它们作为position1和position2的总和加入.我在控制台上得到的值错误为:

I can make the grid points for the blue rectangle too. However, I'm unable to join them inside a single object. I tried to join them as the sum of position1 and position2. I get the value error on the console as:

ValueError: operands could not be broadcast together with shapes (.,.) (.,.)

我该如何解决?

谢谢.

推荐答案

import numpy as np import matplotlib.pyplot as plt bx, by = np.mgrid[0:2, 0:5] gx, gy = np.mgrid[0:10, 5:12] bp = np.vstack((bx.ravel(), by.ravel())) gp = np.vstack((gx.ravel(), gy.ravel())) points = np.hstack((bp, gp)).T # full grid plt.scatter(points[:,0], points[:,1], c='orange', s=200) # green rectangle plt.scatter(gp.T[:,0], gp.T[:,1], c='green', s=50) # blue rectangle plt.scatter(bp.T[:,0], bp.T[:,1], c='blue', s=50) plt.show()

更多推荐

如何在python中合并来自两个矩形的网格网格点?

本文发布于:2023-11-23 04:45:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620138.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   矩形   两个   如何在   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!