The following code snippet
f_folds = 3
fold_quantities = np.array([(0, 0, 0)])
for i in np.arange(n_folds) + 1:
fold_quantities = np.concatenate(
(fold_quantities, [(i, 0, 0)])
)
print(fold_quantities)
gives me
array([[ 0, 0, 0],
[ 1, 0, 0],
[ 2, 0, 0],
[ 3, 0, 0]])
When changing nothing but specifying the dtype of the ndarray
f_folds = 3
fold_quantities = np.array([(0, 0, 0)],
dtype=[('index', int), ('#datapoints', 'int'), ('#pos_labels', 'int')])
for i in np.arange(n_folds) + 1:
fold_quantities = np.concatenate(
(fold_quantities, [(i, 0, 0)])
)
print(fold_quantities)
it throws an error
ValueError Traceback (most recent call last)
<ipython-input-174-649369eed10a> in <module>
5 fold_quantities = np.concatenate(
6 (fold_quantities,
----> 7 [(i, 0, 0)])
8 )
9 print(fold_quantities)
<__array_function__ internals> in concatenate(*args, **kwargs)
ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 1 dimension(s) and the array at index 1 has 2 dimension(s)
This message seems to make no sense. The array dimensions did not change.
How should that be handled? I would like to have the dtype specified since I want to sort the array according to single columns with sorted(key=).