Working from the examples in my answer in your link, Convert array of lists to array of tuples/triple
In [22]: results=np.array([[1. , 0.0342787 ],
...: [0. , 0.04436508],
...: [1. , 0.09101833 ],
...: [0. , 0.03492954],
...: [1. , 0.06059857]])
In [23]: a1 = np.empty((5,), object)
In [24]: a1[:]= [tuple(i) for i in results]
In [25]: a1
Out[25]:
array([(1.0, 0.0342787), (0.0, 0.04436508), (1.0, 0.09101833),
(0.0, 0.03492954), (1.0, 0.06059857)], dtype=object)
or the structured array:
In [26]: a1 = np.array([tuple(i) for i in results], dtype='i,i')
In [27]: a1
Out[27]:
array([(1, 0), (0, 0), (1, 0), (0, 0), (1, 0)],
dtype=[('f0', '<i4'), ('f1', '<i4')])
You got the error because you did not follow my answer:
In [30]: a1[:]= np.array([tuple(i) for i in results])
Traceback (most recent call last):
File "<ipython-input-30-5c1cc6c4105a>", line 1, in <module>
a1[:]= np.array([tuple(i) for i in results])
ValueError: could not broadcast input array from shape (5,2) into shape (5)
The a1[:]=...
assign works for a list, but not for an array.
Note that wrapping the tuple list in an array just reproduces the original results
:
In [31]: np.array([tuple(i) for i in results])
Out[31]:
array([[1. , 0.0342787 ],
[0. , 0.04436508],
[1. , 0.09101833],
[0. , 0.03492954],
[1. , 0.06059857]])
A list of tuples:
In [32]: [tuple(i) for i in results]
Out[32]:
[(1.0, 0.0342787),
(0.0, 0.04436508),
(1.0, 0.09101833),
(0.0, 0.03492954),
(1.0, 0.06059857)]