0

I have the following sample object:

list_sample = [['N', [], None], ['B:maj', [3, 6, 11], 11], ['C#:maj', [1, 5, 8], 1], ['Bb:min', [1, 5, 10], 10], ['Eb:min/b3', [3, 6, 6, 10], 6], ['B:maj', [3, 6, 11], 11], ['C#:maj', [1, 5, 8], 1], ['F#:maj', [1, 6, 10], 6], ['F#:maj', [1, 6, 10], 6], ['B:maj', [3, 6, 11], 11], ['C#:maj', [1, 5, 8], 1], ['Bb:min', [1, 5, 10], 10], ['Eb:min', [3, 6, 10], 3], ['B:maj', [3, 6, 11], 11]]

I would like to transfer this list into a ndarray, so I tried this method suggested in this postDebugging Numpy VisibleDeprecationWarning (ndarray from ragged nested sequences):

np.array(formatted_chords,dtype = object)

But it gives me undesired result like this:

[['N' list([]) None]
 ['B:maj' list([3, 6, 11]) 11]
 ['C#:maj' list([1, 5, 8]) 1]
 ['Bb:min' list([1, 5, 10]) 10]
 ['Eb:min/b3' list([3, 6, 6, 10]) 6]
 ['B:maj' list([3, 6, 11]) 11]]

My target output would a ndarray which looks like this:

[['N',[],None]
 ['B:maj',[3, 6, 11]),11]
 ['C#:maj',[1, 5, 8]),1]
 ['Bb:min',[1, 5, 10]),10]
 ['Eb:min/b3',[3, 6, 6, 10],6]
 ['B:maj',[3, 6, 11],11]]

Can anybody shares how to do this transformation?

  • 2
    what is the reason you want it in an ndarray? Perhaps the solution best for you is not the answer to this question – lucidbrot May 03 '22 at 15:43
  • You got what you want - an array containing strings and lists. If you don't like that display style, stick with the list of lists. – hpaulj May 03 '22 at 16:09
  • When in an object dtype array, a list is displayed as `list([...])`. – hpaulj May 03 '22 at 16:40

0 Answers0