Home > database >  Unable to ravel a numpy array
Unable to ravel a numpy array

Time:12-26

I have a numpy array x = np.array([145100, [ 1,2,3 ], 100.6]) and I wish to ravel it to this: [145100, 1,2,3 , 100.6]

I tried this, but it didn't gave any results:

x = np.ravel(x)

As the shape was still (3,) instead of (5,). What am I missing?

CodePudding user response:

Use numpy.hstack:

import numpy as np

x = np.array([145100, [ 1,2,3 ], 100.6])
x = np.hstack(x)
array([1.451e 05, 1.000e 00, 2.000e 00, 3.000e 00, 1.006e 02])
  • Related