考虑以下 dtype 的 NumPy 数组float32:
In [29]: x = numpy.arange(10, dtype=numpy.float32)
当我将它乘以2usingpytables.Expr时,我得到一个float32数组:
In [30]: tables.Expr('x * 2').eval().dtype
Out[30]: dtype('float32')
然而,当我将它乘以 时2.0,我得到一个float64数组:
In [31]: tables.Expr('x * 2.0').eval().dtype
Out[31]: dtype('float64')
有没有办法以不会导致结果提升为的方式在上述表达式中指定浮点文字float64?
更一般地说,我有一个使用数组的表达式float32,并且我想确保结果也是类型float32(我不介意float64用于中间计算,但我不能将结果存储为float64)。我该怎么做呢?