search

Home  >  Q&A  >  body text

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

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

伊谢尔伦伊谢尔伦2804 days ago1220

reply all(2)I'll reply

  • 阿神

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

    Is it possible that you didn’t import float64
    Of course it’s not right for you to import like this literally. .
    Like this. .

    import numpy as np
    dtype=np.float64

    reply
    0
  • 怪我咯

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

    float64 is a class under numpy. If you want to use float64 without modification, you need to import it like this

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

    If there is no from numpy import float64, use it like this

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

    reply
    0
  • Cancelreply