NumPy speichere einige Arrays auf einmal
Ich arbeite an verschiedenen Formen von Arrays und möchte sie alle mit @ speichernumpy.save
, also denke ich habe
mat1 = numpy.arange(8).reshape(4, 2)
mat2 = numpy.arange(9).reshape(2, 3)
numpy.save('mat.npy', numpy.array([mat1, mat2]))
Es klappt. Aber wenn ich zwei Matrizen mit einer Dimension gleicher Größe habe, funktioniert das nicht.
mat1 = numpy.arange(8).reshape(2, 4)
mat2 = numpy.arange(10).reshape(2, 5)
numpy.save('mat.npy', numpy.array([mat1, mat2]))
Es verursachTraceback (most recent call last): File "<input>", line 1, in <module> ValueError: could not broadcast input array from shape (2,4) into shape (2)
Und beachten Sie, dass das Problem durch @ verursacnumpy.array([mat1, mat2])
und nicht vonnumpy.save
Ich weiß, dass ein solches Array möglich ist:
>> numpy.array([[[1, 2]], [[1, 2], [3, 4]]]) array([[[1, 2]], [[1, 2], [3, 4]]], dtype=object)
Also, alles was ich will ist, zwei Arrays als @ zu speichemat1
undmat2
auf einmal