Consider the following arrays
import numpy as np
a1 = np.array([1,2,3],dtype='object')
a2 = np.array([["A"],["D"],["R"]],,dtype='object')
a3 = np.array([["A","F"],["D"],["R"]],dtype='object')
The following two gives different types of output. Did not expected this. Is this normal?
np.c_[a1,a2]
#array([[1, 'A'],
# [2, 'D'],
# [3, 'R']], dtype=object)
np.c_[a1,a3]
#array([[1, list(['A', 'F'])],
# [2, list(['D'])],
# [3, list(['R'])]], dtype=object)
Why the first works and not the second expression? I do not see any difference between a2 and a3. Further, which concatenation method (c_, stack, concatenation) would output the same type of output without having to add other lines of code such as checking the output data type and converting it as needed.
np.concatenate((a1,a2),axis=0) # Error: ValueError: all the input arrays must have same number of dimensions
np.concatenate((a1,a3),axis=0) # works
#array([1, 2, 3, list(['A', 'F']), list(['D']), list(['R'])], dtype=object)
a2anda3. They are very different.