首页 > 解决方案 > UFuncTypeError,我收到此错误。我该如何解决这个问题,以便我可以读取变量

问题描述

运行代码时出现此错误:

UFuncTypeError: ufunc 'multiply' 不包含签名匹配类型的循环 (dtype('<U32'), dtype('<U32')) -> dtype('<U32')

我是 python 和编码的新手,所以我希望在这里提供问题的相关信息。

我可以打印所有其他变量,但是当我尝试打印 WindPower_capacity_factor_monthly 时出现错误。不确定如何从这里处理我的数据。

这是我的代码:

#import matplotlib.pyplot as plt
import numpy as np
#from mpl_toolkits.basemap import Basemap

nc = Dataset('/Users/fredrikvonschlanbusch/Documents/Skole/Master/WindPower_capacity_factor_monthly.nc')

cf = nc['WindPower_capacity_factor_monthly'][:]

print(cf)

nc 看起来像这样:

root group (NETCDF4 data model, file format HDF5):
    description: NORwegian hindcast Archive Wind Power data set (NORA3-WP)
    institution: Geophysical Institute, Bergen offshore wind centre, University of Bergen, Norway
    production: Created using MatLab (version 2018b)
    author: Ida M. Solbrekke (email: ida.solbrekke@gfi.uib.no) and Asgeir Sorteberg (email: Asgeir.Sorteberg@uib.no)
    date: 15-Aug-2021
    dimensions(sizes): X(652), Y(1149), T(288), Z(3), stringlength(15), M(1), methodlength(1000), turbine(3)
    variables(dimensions): float64 lon(Y, X), float64 lat(Y, X), float64 projection_lambert(), float64 time(T), float32 hub_heights(Z), |S1 turbine_name(stringlength, Z), float32 turbine_rated_power(Z), float32 turbine_cut_in_wind_speed(Z), float32 turbine_rated_wind_speed(Z), float32 turbine_cut_out_wind_speed(Z), |S1 method(methodlength, M), float32 WindPower_capacity_factor_monthly(T, M, turbine, Y, X)

cf 看起来像这样:

float32 WindPower_capacity_factor_monthly(T, M, turbine, Y, X)
    long_name: WindPower_capacity_factor_monthly
    standard_name: WindPower_capacity_factor_monthly
    units: Percentage (%)
    scale_factor: 1
    coordinates: lat lon
    variable_description: Capacity factor is here the ratio between the monthly generated wind power and the monthly maximum possible wind power output
unlimited dimensions: T
current shape = (288, 1, 3, 1149, 652)
filling on, default _FillValue of 9.969209968386869e+36 used

标签: pythonerror-handling

解决方案


推荐阅读