Python: Making numpy default to float32

后端 未结 3 555
北荒
北荒 2020-12-03 10:27

Is there any clean way of setting numpy to use float32 values instead of float64 globally?

3条回答
  •  清歌不尽
    2020-12-03 10:58

    For each function you can overload by:

    def array(*args, **kwargs):
        kwargs.setdefault("dtype", np.float32)
        return np.array(*args, **kwargs)
    

    As posted by njsmith on github

提交回复
热议问题