0

I am trying to create a 2D matrix, that each datapoint is a 2D array. / 10 \ / |a1_0|a2_0|a3_0|....| |a1_1|..............| 1000 |a1_2|..............| |...................| \ |...................|

where a1_0, a1_1, a2_0 are all (1025, 16) array.

To my understanding, that means I have to create a matrix with shape = (10, 1000, 1025, 16). (please let me know if I'm wrong)

And all I have are a1_0, a1_1, a2_0...

So my question is how to concatenate these arrays with most efficient ways if I have to concatenate 2 numpy array into a new dimension?

I've tried np.vstack() and np.concatenate() but seem not right.


I am using a function to transfer a piece of audio into a spectrogram (which is a picture), the function will return a variable called spec, which is a (1025, 16) numpy array

Therefore, at first I was trying to do:

for a0 ~ a9, concatenate:
   for a1_1 ~ a1_999, concatenate:
       spec = gen_spectrogram (audio)
6
  • How are all these arrays stored? Commented Nov 13, 2018 at 9:49
  • I am using a function to transfer a piece of audio into a spectrogram (which is a picture), the function will return a variable spec, which is a (1025, 16) numpy array Commented Nov 13, 2018 at 9:53
  • Initialize array out with shape : (10, 1000, 1025, 16) and then iteratively assign : out[i,j] = ... Commented Nov 13, 2018 at 9:56
  • Sorry I don't understand with the out thing, is it a numpy method? Commented Nov 13, 2018 at 10:10
  • @Divakar Are you suggesting that I can create an empty array with shape (10, 1000, 1025, 16) and then iteratively assign last 2 numbers? Commented Nov 13, 2018 at 10:14

1 Answer 1

2

First stack ai_0, ..., ai_999:

ci = np.stack([ai_0,...,ai_999])

Then stack c0, ..., c9

conc = np.stack([c0, ..., c9])

The result should be of shape (10, 1000, 1025, 16)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.