在Python中生成热图时出现错误:ValueReror:必须通过2D输入。 shape =()

发布于 2025-01-28 13:08:30 字数 1217 浏览 1 评论 0原文

在Python中生成H3矩的地图时,我会遇到错误,以获取名为“ Image_test”的图像文件。错误显然是针对我为H3获得的值的形状。我的目标是仅在代码中从H3 [YCELL] [XCELL]中获得的H3值,然后使用该值在XY网格中创建一个红蓝色热图。我的驱动器中指向我的代码(image_stats.ipynb)的链接在下面。该代码使用文件“ image_test”,需要下载才能运行代码。 https://drive.google.com/drive/folders/1gxwsuxsohhanv5qv5qv-c1f-c1f4keuwelkmmrs?usp =

the主要问题可能是在代码的这段段落中

for ycell in range(8):
    for xcell in range(13):
        #cells[ycell][xcell] = np.array(vz_new[(y_new == ycell) & (x_new == xcell)],dtype=object)
        cells[ycell][xcell] = vz_new[(y_new == ycell) & (x_new == xcell)]
        #[ i for i in cells[ycell][xcell] if (math.inf not in i) and (math.nan not in i) ]
        
        h3[ycell][xcell] = get_h3(cells[ycell][xcell]) 
        #print(cells[ycell][xcell])
        #print(h3[ycell][xcell])
        
        
        #print('SHAPE IS=', h3[ycell][xcell].shape)
fig, ax = plt.subplots()
# heatmap
ax=sns.heatmap(h3[ycell][xcell], cmap='RdBu')
ax.invert_yaxis()
plt.show()

sharing sharing 用于完整代码。感谢您的帮助!如果需要,请要求澄清。

注意:H3就像列表。打印时看起来如下。

I am getting errors while generating maps of h3 moments in python for an image file called "image_test". The error apparently is for the shape of the values that I am getting for h3. My goal is to just take the h3 values that I get from h3[ycell][xcell] in my code and then use the values to create a red-blue heatmap in the x-y grid. The link to my code (image_stats.ipynb) in my drive is below. The code uses a file "image_test" which needs to be downloaded for code to run.
https://drive.google.com/drive/folders/1gXWSuxsOHHaNV5Qv-C1f4kEUwElKMmRS?usp=sharing

The main issue might be in this snippet of the code:

for ycell in range(8):
    for xcell in range(13):
        #cells[ycell][xcell] = np.array(vz_new[(y_new == ycell) & (x_new == xcell)],dtype=object)
        cells[ycell][xcell] = vz_new[(y_new == ycell) & (x_new == xcell)]
        #[ i for i in cells[ycell][xcell] if (math.inf not in i) and (math.nan not in i) ]
        
        h3[ycell][xcell] = get_h3(cells[ycell][xcell]) 
        #print(cells[ycell][xcell])
        #print(h3[ycell][xcell])
        
        
        #print('SHAPE IS=', h3[ycell][xcell].shape)
fig, ax = plt.subplots()
# heatmap
ax=sns.heatmap(h3[ycell][xcell], cmap='RdBu')
ax.invert_yaxis()
plt.show()

Not posting full code or error here because too long, so please check google drive link for full code. Thanks for any help! Please ask for clarification if needed.

NOTE: h3 is like a list of lists. looks like the following when printed.
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文