我有一個汽車列表,想將其轉換為多維數組>>> cars = [[[2,1],[1,1]],[[0,2],[0,1],[0,0]],[[5,0],[5,1],[5,2]],[[1,5],[2,5]]]>>> cars_np = np.array(cars)>>> cars_np.shape(4,)>>> cars_nparray([list([[2, 1], [1, 1]]), list([[0, 2], [0, 1], [0, 0]]), list([[5, 0], [5, 1], [5, 2]]), list([[1, 5], [2, 5]])], dtype=object) # an array of lists is not what i want>>> cars_np = np.array([np.array(car) for car in cars])>>> cars_np.shape(4,)>>> cars_nparray([array([[2, 1], [1, 1]]), array([[0, 2], [0, 1], [0, 0]]), array([[5, 0], [5, 1], [5, 2]]), array([[1, 5], [2, 5]])], dtype=object) # an array of arrays is not what i want使用此列表可以正常工作:>>> l = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]>>> l_np = np.array(l)>>> l_np.shape(2, 2, 2) # multidimensional array as expected我與第一個例子有什么關系?
如何從 Nesteld 列表中獲取 3 維 numpy 數組
慕田峪9158850
2022-10-25 11:02:43