将numpy数组类型和值从Float64转换为Float32 [英] Convert numpy array type and values from Float64 to Float32

查看:1900
本文介绍了将numpy数组类型和值从Float64转换为Float32的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将类型从Float64的阈值数组(来自scikit Learn的隔离林的点刺文件)转换为Float32

I am trying to convert threshold array(pickle file of isolation forest from scikit learn) of type from Float64 to Float32

for i in range(len(tree.tree_.threshold)):
    tree.tree_.threshold[i] = tree.tree_.threshold[i].astype(np.float32)

然后打印

for value in tree.tree_.threshold[:5]:
    print(type(value))
    print(value)

我得到的输出是:

<class 'numpy.float64'>
526226.0
<class 'numpy.float64'>
91.9514312744
<class 'numpy.float64'>
3.60330319405
<class 'numpy.float64'>
-2.0
<class 'numpy.float64'>
-2.0

我没有正确转换为Float32.我想将值及其类型转换为Float32,有人对此有任何解决方法吗?

I am not getting a proper conversion to Float32. I want to convert values and their type to Float32, Did anybody have any workaround this ?

推荐答案

实际上,我很努力,但不能做到 "sklearn.tree._tree.Tree"对象不可写.

Actually i tried hard but not able to do as the 'sklearn.tree._tree.Tree' objects is not writable.

在生成PMML文件时会导致精度问题,所以我 在那边提出了一个错误,他们为此提供了更新的解决方案 不会在内部将其转换为Float64.

It is causing a precision issue while generating a PMML file, so i raised a bug over there and they gave an updated solution for it by not converting it in to the Float64 internally.

有关更多信息,您可以点击以下链接: 精度问题

For more info, you can follow this link: Precision Issue

这篇关于将numpy数组类型和值从Float64转换为Float32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆