【问题标题】:Matlab typecast transfer to python 3.7Matlab 类型转换转移到 python 3.7
【发布时间】:2021-03-26 18:22:29
【问题描述】:

我有一些 Matlab 的摘录代码。我想转移到python3.7代码。但是我发现一些Matlab函数我不能转移到python 3.7它,比如函数类型转换,以及Matlab中的single。 因此,我怎样才能编写 python 代码并获得相同的结果? 谢谢

这是 Matlab 代码

AA= uint32(3249047552)
DPD = typecast(AA,'single');    
Print(DPD)

DPD = -21.0664

【问题讨论】:

  • AA 转换为 base 2,然后使用 IEEE 标准 754 单精度计算相应的单值。
  • 请不要在收到答复后更改问题。您的编辑使答案似乎错误。相反,接受答案:stackoverflow.com/help/someone-answers

标签: matlab python-3.7 uint32


【解决方案1】:

使用numpy,您可以使用view()

# Define your uint32 number
x = np.array(3249047552, dtype=np.uint32)
# Get the equivalent bitwise single number
x.view(np.single)
# output: -21.066406

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-25
    • 2016-08-19
    • 1970-01-01
    相关资源
    最近更新 更多