Python numpy数组乘法是否总是上溯到64位?

Python numpy数组乘法是否总是上溯到64位?,python,numpy,scipy,Python,Numpy,Scipy,当numpy数组被乘法时,它是否总是上溯到64位 scipy稀疏矩阵乘法也是这样吗 如果是这样的话,在64位操作系统上是否有一种通用方法可以强制乘法到32位(dtype=numpy.float32) 此选项来自Windows 32位框: >>> import numpy >>> from scipy import sparse >>> row = numpy.array([0,0,1,2,2,2], dtype=numpy.int32) &

当numpy数组被乘法时,它是否总是上溯到64位

scipy稀疏矩阵乘法也是这样吗

如果是这样的话,在64位操作系统上是否有一种通用方法可以强制乘法到32位(dtype=numpy.float32)

此选项来自Windows 32位框:

>>> import numpy
>>> from scipy import sparse

>>> row = numpy.array([0,0,1,2,2,2], dtype=numpy.int32)
>>> col = numpy.array([0,2,2,0,1,2], dtype=numpy.int32)
>>> data = numpy.array([1,2,3,4,5,6], dtype=numpy.int32)

>>> A = sparse.csr_matrix((data,(row,col)), shape=(3,3), dtype=numpy.int32)
>>> x = numpy.array([8.0, 4.0, 2.0], dtype=numpy.float32)
>>> b = A * x.T

>>> b
array([ 12.,   6.,  64.])

>>> type(b)
<type 'numpy.ndarray'>

>>> for i in xrange(3): print type(b[i])
<type 'numpy.float64'>
<type 'numpy.float64'>
<type 'numpy.float64'>
导入numpy >>>从scipy导入稀疏 >>>row=numpy.array([0,0,1,2,2,2],dtype=numpy.int32) >>>col=numpy.array([0,2,2,0,1,2],dtype=numpy.int32) >>>data=numpy.array([1,2,3,4,5,6],dtype=numpy.int32) >>>A=sparse.csr_矩阵((数据,(行,列)),shape=(3,3),dtype=numpy.int32) >>>x=numpy.array([8.0,4.0,2.0],dtype=numpy.float32) >>>b=A*x.T >>>b 数组([12,6,64.])) >>>类型(b) >>>对于X范围(3)中的i:打印类型(b[i])
获取所需的
dtype
的最佳选择是确保乘法中涉及的两个数组都是完全相同的
dtype
(=float32),首先:

A = sparse.csr_matrix((data,(row,col)), shape=(3,3), dtype=numpy.float32)
x = numpy.array([8.0, 4.0, 2.0], dtype=numpy.float32)
(A * x.T).dtype
=> dtype('float32')

请给出一个乘法示例,其中输入为32位,输出为64@shx2有问题的示例。适用于32位和64位操作系统。这是一个奇怪的向上转换规则,因为您希望它向上转换到A和x之间的最高数据类型,而不是选择操作系统大小。谢谢你-布里尔!