Abdul Rehman
Abdul Rehman

Reputation: 11

How do i plot 2d array by coverting 2d arrays into two one 1d arrays?

I have Latitude and Depth, I want to seprate these two arrays in form of numpy array. [['Latitude' 'Depth'] ['28.00303425' '5067.9097'] ['28.00304059' '5068.656'] ... ['28.01996016' '5067.0303'] ['28.01996016' '5067.0234'] ['28.01996017' '5066.8833']]

Upvotes: 0

Views: 46

Answers (1)

DrCorgi
DrCorgi

Reputation: 166

Try this following code snippet. The zip command can be used to split the 2d array into two separate columns/arrays. I used the index "1:" to remove the top row, containing the column names.

data=np.asarray([['Latitude','Depth'],
      ['28.00303425','5067.9097'],
      ['28.00304059','5068.656'],
      ['28.01996017','5066.8833']])

lat, depth = zip(*data[1:])
print(np.asarray(lat))
print(np.asarray(depth))

Output

['28.00303425' '28.00304059' '28.01996017']
['5067.9097' '5068.656' '5066.8833']

Upvotes: 1

Related Questions