Only Size-1 Arrays Can Be Converted To Python Scalars Error

这篇博客探讨了在Python中遇到'Only size-1 arrays can be converted to Python scalars'错误的原因和解决方案。文章详细解释了该错误通常发生在尝试将多维数组转换为标量值时,并提供了若干修复方法,包括使用numpy的函数和修改代码逻辑来避免直接转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考
https://www.pythonpool.com/only-size-1-arrays-can-be-converted-to-python-scalars-error-solved/

站号 lon lat 海拔高度 cheng 0 59417 106.8540 22.3397 0 0.4 1 59419 106.7400 22.0644 0 0.4 2 53276 112.9010 42.3978 0 0.5 3 59421 107.1660 22.8594 0 0.3 4 59427 107.0390 22.1103 0 0.4 ... ... ... ... ... ... 1165 50658 125.7880 48.0842 0 1.4 1166 50659 126.2400 48.0539 0 1.3 1167 51430 81.1480 43.8317 0 0.5 1168 51431 81.3264 43.9406 0 1.1 1169 56319 95.3175 29.3128 0 0.8 1170 rows × 5 columns 0.0 32.0 --------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[31], line 63 61 # 对非中国区域的数据进行掩码操作 62 xx, yy = m(grid_lon, grid_lat) # 将经纬度转换为投影坐标 ---> 63 mask = ~m.is_land(xx, yy) | ((xx < m.xmin) | (xx > m.xmax)) | ((yy < m.ymin) | (yy > m.ymax)) 64 masked_data = np.ma.array(interpolated_accuracy, mask=mask) 66 # 绘制等高线填充图 File e:\Aminiconda\envs\tyingb\lib\site-packages\mpl_toolkits\basemap\__init__.py:2051, in Basemap.is_land(self, xpt, ypt) 2049 landpt = False 2050 for poly in self.landpolygons: -> 2051 landpt = _geoslib.Point((xpt,ypt)).within(poly) 2052 if landpt: break 2053 lakept = False File src\\_geoslib.pyx:468, in _geoslib.Point.__init__() TypeError: only size-1 arrays can be converted to Python scalars --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[42], line 2 1 shp = geopandas.read_file('E:/text/长春站点/长春市.shp') ----> 2 interpolated_accuracy.rio.set_spatial_dims(x_dim="lon", y_dim="lat", inplace=True) 3 interpolated_accuracy.rio.write_crs("WGS1984", inplace=True)#视自己的数据坐标系而定,这里是比较广泛的WGS1984 4 d = interpolated_accuracy.rio.clip(shp.geometry.apply(mapping),shp.crs,drop=False) AttributeError: 'numpy.ndarray' object has no attribute 'rio'
03-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值