python - np.astype 不改变数组类型
问题描述
我正在摄取许多数据集,其中包括纬度和经度值。其中之一的 lat 和 lon 字段设置为 float64,而其他所有人都使用 float32。所以,我最初试图简单地转换类型 - 除了类型转换似乎没有发生。
更糟糕的是,我没有收到任何错误消息,因此很难排除故障。
我这里有一些明显的错误吗?lat_ref 应该存在于一个数组中,最初是一个 Float64。我想用一个值为 Float32 的数组替换该数组,我不介意这些值是否被截断以匹配 float32,因为带有 float64 的纬度将以纳米为单位测量。
示例代码:
lat_ref = nc.variables['lat'][:] #This is where I read in the lat from my data
lat_ref = lat_ref.astype(np.float32)
print("The shape of lat_ref is: " + str(np.shape(lat_ref)))
print("The dtype of lat_ref is: " + str(lat_ref.dtype))
打印的结果是:
The shape of lat_ref is: (681,)
The dtype of lat_ref is: float64
我的其他数据集响应打印(没有 .astype 转换),如下所示:
The shape of lat_ref is: (408,)
The dtype of lat_ref is: float32
我希望转换使 lat_ref 像上面那样。
解决方案
推荐阅读
- c++ - 不能将 range-v3 与 boost 图形库一起使用
- drake - 如何使用 ComPositionConstraint 做逆运动学?
- r - 使用 R 的动画地图
- python - 检查哪些理解列表输出不是 None 并转到相应的功能
- swift - 图中朋友的递归函数逻辑朋友
- javascript - 立即获取具有解析时间的今天日期
- laravel - 如何在 Windows PC 上安装 laravel 8 项目?
- jquery - 显示和隐藏
- javascript - 为什么我们将 textarea 高度设置为'0px',然后再将其设置为等于它的 scrollHeight 以自动调整 textarea 的大小?
- node.js - 如何在expressjs/nodejs中在同一控制器和同一路由下开发多个get路由器功能?