I have two different arrays, one with strings and another with ints. I want to concatenate them, into one array where each column has the original datatype. My current solution for doing this (see below) converts the entire array into dtype = string, which seems very memory inefficient.
combined_array = np.concatenate((A, B), axis = 1)
Is it possible to mutiple dtypes in combined_array when A.dtype = string and B.dtype = int?
One approach might be to use a record array. The "columns" won’t be like the columns of standard numpy arrays, but for most use cases, this is sufficient:
Note that you can also do something similar with a standard array by specifying the datatype of the array. This is known as a "structured array":
The difference is that record arrays also allow attribute access to individual data fields. Standard structured arrays do not.