0

I'm working on a tensorflow project that learns from mp3 files. I have opened the binary data and read it. Then I have converted the binary to ascii. Then I have confirmed that the conversion. But then when I go to append it to a numpy array, it appends blank data.

    dataset = np.ndarray(shape=(len(image_files)),
                     dtype=np.dtype('a16'))
    f = open(image_file, 'rb')
    temp = f.read()
    # sound = AudioSegment.from_mp3(image_file)
    # raw_data = sound._data
    audio_array = binascii.b2a_base64(temp)
    # print(audio_array)
    np.append(dataset, audio_array)
    print(dataset)
    print(COUNT)

when I print(audio_array) I get the following

czDne2AxSfpq0DMK9MjrzBw2/F6sMWm/XD47FTN0aXUkq/kIKP2mK3satPUWf9/zTV/t/dTf1Lf//uSBOmNA3pZU6sPOvJ0q0p2PUn2SfFjVAesq8FQrCuo9BUh1f9zRCt//yh7OOuhMogrixdsGrTHd+tGSSaAkPrfqnQ48vFMd6fSBOErLeOipQXe7zkuSt7aFR5J7v3MA3b+gMYpO32b0Kxo/ee/WcN/727XSS/p/1H/8hf5cBCEwWAHBfxdhEKHVomiae73PzIai5...

But then when I go to print dataset I get the following:

['' '' '' ..., '' '' '']
2

2 Answers 2

1

np.append(dataset, audio_array) returns a new array; it does not modify dataset. So change

np.append(dataset, audio_array)

to

dataset = np.append(dataset, audio_array)
Sign up to request clarification or add additional context in comments.

Comments

0

Try and use the help function of python, it is really helpful. In this case notice:

help(numpy.append)

Outputs: ....

    Returns
    -------
    append : ndarray
        A copy of `arr` with `values` appended to `axis`.  Note that
        `append` does not occur in-place: a new array is allocated and
        filled.  If `axis` is None, `out` is a flattened array.

Which means that the passed array isn't modified but copied instead, you must store the return value in dataset:

dataset = numpy.append(dataset, audio_array)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.