Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Numpy structured array Nitram Programmer named Tim Posts: 9 Threads: 2 Joined: Aug 2019 Reputation: 0 Likes received: 0 #1 Sep-17-2019, 12:02 PM (This post was last modified: Sep-17-2019, 12:02 PM by Nitram. Edited 1 time in total.) Hi all, I am fairly new to Python and teaching myself. I am working on importing data from a txt file into a NumPy structured array. I have loaded the data in to give three fields: the IATA code of an airport, the airport's latitude, and it's longitude... ``` import numpy as np fname = 'busiest_airports.txt' dtype1 = np.dtype([('IATA', '|S4'), ('latitude', 'f8'), ('longitude', 'f8')]) a = np.loadtxt(fname, dtype = dtype1, usecols = (0, -2, -1)) print(a) ``` This gives me the following array... ``` array([(b'FRA', 50.026, 8.543), (b'DEN', 39.862, -104.673), (b'BKK', 13.681, 100.747), (b'SYD', -33.946, 151.177), (b'GRU', -23.432, -46.47 ), (b'CLT', 35.214, -80.943), (b'SFO', 37.619, -122.375), (b'IAH', 29.984, -95.341), (b'ATL', 33.637, -84.428), (b'ICN', 37.469, 126.451), (b'DFW', 32.897, -97.038), (b'HND', 35.552, 139.78 ), (b'LAS', 36.08 , -115.152), (b'PHX', 33.434, -112.012), (b'PVG', 31.143, 121.805), (b'DXB', 25.253, 55.364), (b'MIA', 25.793, -80.291), (b'IST', 40.977, 28.815), (b'AMS', 52.309, 4.764), (b'CAN', 23.392, 113.299), (b'LAX', 33.943, -118.408), (b'CGK', -6.126, 106.656), (b'LHR', 51.477, -0.461), (b'JFK', 40.64 , -73.779), (b'SIN', 1.35 , 103.994), (b'CDG', 49.013, 2.55 ), (b'HKG', 22.309, 113.915), (b'ORD', 41.979, -87.905), (b'KUL', 2.746, 101.71 ), (b'PEK', 40.08 , 116.585)], dtype=[('IATA', 'S4'), ('latitude', '

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post converting dataframe to int numpy array glennford49 1 238 Apr-04-2020, 06:15 AM Last Post: snippsat Replacing sub array in Numpy array ThemePark 5 304 Apr-01-2020, 01:16 PM Last Post: ThemePark How to prepare a NumPy array which include float type array elements subhash 0 220 Mar-02-2020, 06:46 AM Last Post: subhash numpy.where array search for string in just one coordinate adetheheat 1 355 Jan-09-2020, 07:09 PM Last Post: paul18fr memory issue loading movie to numpy array djf123 1 282 Nov-07-2019, 06:19 AM Last Post: ThomasL numpy.copy / numpy.delete paul18fr 3 637 Jul-26-2019, 01:51 PM Last Post: paul18fr AttributeError: module 'numpy' has no attribute 'array aapurdel 7 12,397 May-29-2019, 02:48 AM Last Post: heiner55 Array in numpy Truman 5 4,795 May-26-2019, 10:14 AM Last Post: snippsat [split] Array in numpy aapurdel 1 506 May-25-2019, 08:05 PM Last Post: buran [numpy]add a value to an array elmismo999 1 658 May-23-2019, 04:15 PM Last Post: michalmonday

Forum Jump:

Users browsing this thread: 1 Guest(s)