python - transform an array of array to an array of numbers -
I have an array of values and repeatedly an array of
& gt; & Gt; & Gt; X = NP. Color (5)> gt; & Gt; & Gt; X array ([0, 1, 2, 3, 4]) & gt; & Gt; & Gt; N = np.random.randint (1,3,5)> & Gt; & Gt; N array ([2, 1, 1, 2, 2]) and I
gt; & Gt; Y = np.array ([np.repeat (x [i], n [i]) for category (5)])> gt; & Gt; & Gt; Array ([0, 0]), array ([1]), array ([2]), array ([3, 3]), array ([4, 4]), dtype = object) But I want to have my result array ([0, 0, 1, 2, 3, 3, 4, 4]). How can I do this?
I think it's easier than you are making:
< Code> & gt; & Gt; & Gt; X = NP. Color (5)> gt; & Gt; & Gt; Y = np.array ([2, 1, 1, 2, 2]) & gt; & Gt; & Gt; Np.repeat array (x, y) ([0, 0, 1, 2, 3, 3, 4, 4])
Comments
Post a Comment