Maison  >  Questions et réponses  >  le corps du texte

python3.x - python3.5的numpy设置array为float64,报错"name float64 is not defined"

trainWeights = gradDescent(np.array(trainingSet,dtype=float64), trainingLabels)

把dtype设置为float64会报错 NameError: name 'float64' is not defined

但是如果去掉"dtype=float64"会出现warning:DataConversionWarning: Data with input dtype <U3 was converted to float64 by MinMaxScaler.
warnings.warn(msg, DataConversionWarning) 提醒被转换成了float64

请问应该如何显式转换呢?

伊谢尔伦伊谢尔伦2742 Il y a quelques jours1185

répondre à tous(2)je répondrai

  • 阿神

    阿神2017-04-17 17:50:06

    会不会,你没有import float64
    你这样字面上这样import当然不对啊。。
    这样。。

    import numpy as np
    dtype=np.float64

    répondre
    0
  • 怪我咯

    怪我咯2017-04-17 17:50:06

    float64是numpy下的一个类,你如果想要前面不加修饰的使用float64需要这样导入

    import numpy as np
    from numpy import float64
    
    
    c = np.array([], dtype=float64)
    

    如果没有from numpy import float64,使用时要这样

    c = np.array([], dtype=np.float64)

    répondre
    0
  • Annulerrépondre