Issue converting list to NumPy array

前端 未结 2 1114
一整个雨季
一整个雨季 2021-01-21 09:14

I have a list that consits of 2000 rows and 88200 columns:

testlist = list(split_audio_to_parts(audio, self.sample_rate, self.audio_index))

deb

2条回答
  •  离开以前
    2021-01-21 09:58

    You have a list of arrays. If each array in your list does not have the same length, your conversion will not be successful.

    Here is a minimal example.

    A = [np.array([1, 2]), np.array([4, 5, 6])]
    
    A_2 = np.array(A)
    # array([array([1, 2]), array([4, 5, 6])], dtype=object)
    
    A_2.shape
    # (2,)
    

    If the lengths of your arrays are aligned, you will find no problem:

    B = [np.array([1, 2, 3]), np.array([4, 5, 6])]
    
    B_2 = np.array(B)
    # array([[1, 2, 3],
    #        [4, 5, 6]])
    
    B_2.shape
    # (2, 3)
    

    To check the sizes of your arrays, you can use set:

    array_sizes = set(map(len, A))
    

提交回复
热议问题