Subarray 2D único e irregular [duplicado]
Esta pergunta já tem uma resposta aqui:
Encontre linhas exclusivas em numpy.array 20 respostasTenho uma matriz numpy 3D e quero apenas sub-matrizes 2D única
Entrada
[[[ 1 2]
[ 3 4]]
[[ 5 6]
[ 7 8]]
[[ 9 10]
[11 12]]
[[ 5 6]
[ 7 8]]]
Saída
[[[ 1 2]
[ 3 4]]
[[ 5 6]
[ 7 8]]
[[ 9 10]
[11 12]]]
Eu tentei converter sub-matrizes em string (método tostring ()) e, em seguida, use np.unique, mas depois de transformar em array numpy, ele excluiu os últimos bytes de \ x00, então não posso transformá-lo novamente com np.fromstring ( ).
Exemplo
import numpy as np
a = np.array([[[1,2],[3,4]],[[5,6],[7,8]],[[9,10],[11,12]],[[5,6],[7,8]]])
b = [x.tostring() for x in a]
print(b)
c = np.array(b)
print(c)
print(np.array([np.fromstring(x) for x in c]))
Saída
[b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00', b'\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00', b'\t\x00\x00\x00\n\x00\x00\x00\x0b\x00\x00\x00\x0c\x00\x00\x00', b'\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00']
[b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04'
b'\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08'
b'\t\x00\x00\x00\n\x00\x00\x00\x0b\x00\x00\x00\x0c'
b'\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08']
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-86-6772b096689f> in <module>()
5 c = np.array(b)
6 print(c)
----> 7 print(np.array([np.fromstring(x) for x in c]))
<ipython-input-86-6772b096689f> in <listcomp>(.0)
5 c = np.array(b)
6 print(c)
----> 7 print(np.array([np.fromstring(x) for x in c]))
ValueError: string size must be a multiple of element size
Eu também tentei ver, mas realmente não sei como usá-lo. Você pode me ajudar por favor