I currently have a numpy multi-dimensional array (of type float) and a numpy column array (of type int). I want to combine the two into a mutli-dimensional numpy array.
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 the types of the arrays are different:
>> type(dates[0])
<type 'numpy.int64'>
>> type(data[0,0])
<type 'numpy.float64'>
Yes, a numpy array can store different data String, Integer, Complex, Float, Boolean.
Yes, if you use numpy structured arrays, each element of the array would be a "structure", and the fields of the structure can have different datatypes.
The NumPy ndarray class is used to represent both matrices and vectors. A vector is an array with a single dimension (there's no difference between row and column vectors), while a matrix refers to an array with two dimensions. For 3-D or higher dimensional arrays, the term tensor is also commonly used.
NumPy apes the concept of row and column vectors using 2-dimensional arrays. An array of shape (5,1) has 5 rows and 1 column. You can sort of think of this as a column vector, and wherever you would need a column vector in linear algebra, you could use an array of shape (n,1) .
import numpy as np
np.column_stack((dates, data))
The types are cast automatically to the most precise, so your int array will be converted to float.
The types don't matter, you should reshape dates to be (1251, 1) before using hstack.
Ps. The ints will be cast to float.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With