Closed
Description
Describe the issue:
I guess result dtype should be same as input dtype, but code below is not.
import numpy as np
x = np.array([0.04399043, -0.26885903])
y = np.array([-0.99222845, -0.1244299])
x = x.astype("float32")
y = y.astype("float32")
z = np.dot(x, y)
print(z.ndim) # 0
print(z.shape) # ()
print(z.dtype) # float32
print((z**2).dtype) # float64
and when z
is reshaped to [1]
, dtype is consistent with input as expected
import numpy as np
x = np.array([0.04399043, -0.26885903])
y = np.array([-0.99222845, -0.1244299])
x = x.astype("float32")
y = y.astype("float32")
z = np.dot(x, y).reshape([1]) # reshape to [1]
print(z.ndim) # 1
print(z.shape) # (1,)
print(z.dtype) # float32
print((z**2).dtype) # float32
Reproduce the code example:
import numpy as np
x = np.array([0.04399043, -0.26885903])
y = np.array([-0.99222845, -0.1244299])
x = x.astype("float32")
y = y.astype("float32")
z = np.dot(x, y)
print(z.ndim) # 0
print(z.shape) # ()
print(z.dtype) # float32
print((z**2).dtype) # float64
import numpy as np
x = np.array([0.04399043, -0.26885903])
y = np.array([-0.99222845, -0.1244299])
x = x.astype("float32")
y = y.astype("float32")
z = np.dot(x, y).reshape([1]) # reshape to [1]
print(z.ndim)
print(z.shape)
print(z.dtype)
print((z**2).dtype)
Error message:
No response
NumPy/Python version information:
1.21.6 could reproduce this BUG.
Context for the issue:
No response