Python,hstack不同类型的列numpy数组(列向量)

ben*_*oss 4 python numpy

我目前有一个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
Run Code Online (Sandbox Code Playgroud)

要显示数组的类型不同:

>> type(dates[0])
<type 'numpy.int64'>
>> type(data[0,0])
<type 'numpy.float64'>
Run Code Online (Sandbox Code Playgroud)

Gri*_*ees 10

import numpy as np

np.column_stack((dates, data))
Run Code Online (Sandbox Code Playgroud)

这些类型会自动转换为最精确的类型,因此您的int数组将转换为float.