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 像上面那样。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)