Python, hstack column numpy arrays (column vectors) of different types

Currently, I have a multidimensional multidimensional array (of type float) and an array of numpy columns (of type int). I want to combine these two into a multidimensional numpy matrix.

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 

To show that array types are different:

 >> type(dates[0]) <type 'numpy.int64'> >> type(data[0,0]) <type 'numpy.float64'> 
+4
source share
3 answers
 import numpy as np np.column_stack((dates, data)) 

Types are passed automatically most accurately, so your int array will be converted to float.

+10
source

Types do not matter, you must change the dates (1251, 1) before using hstack.

Ps. Interfaces will be cast for float.

+1
source

test = numpy.hstack((dates[:,numpy.newaxis], data))

0
source

Source: https://habr.com/ru/post/1388693/


All Articles