我现在有一个numpy多维数组(float类型)和一个numpy列数组(int类型)。我想把它们组合成多维的numpy数组。
import numpy
>> dates.shape
(1251,)
>> data.shape
(1251,10)
>> test = numpy.hstack((dates, data))
ValueError: all the input arrays must have same number of dimensions
要显示数组的类型不同,请执行以下操作:
>> type(dates[0])
<type 'numpy.int64'>
>> type(data[0,0])
<type 'numpy.float64'>
这些类型无关紧要,在使用hstack之前,您应该将日期重塑为(1251,1)。
注:整数将被转换为浮点数。
类型将自动转换为最精确的类型,因此您的int数组将被转换为float。
test = numpy.hstack((dates[:,numpy.newaxis], data))
相关问题 更多 >
编程相关推荐