In [1]:
import numpy as np
In [3]:
countries = np.array([
'Afghanistan', 'Albania', 'Algeria', 'Angola', 'Argentina',
'Armenia', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas',
'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium',
'Belize', 'Benin', 'Bhutan', 'Bolivia',
'Bosnia and Herzegovina'])
In [4]:
employment = np.array([
55.70000076, 51.40000153, 50.5 , 75.69999695,
58.40000153, 40.09999847, 61.5 , 57.09999847,
60.90000153, 66.59999847, 60.40000153, 68.09999847,
66.90000153, 53.40000153, 48.59999847, 56.79999924,
71.59999847, 58.40000153, 70.40000153, 41.20000076
])
In [5]:
print countries[0]
In [6]:
print countries[3]
In [7]:
print countries[0:3]
print countries[:3]
print countries[17:]
print countries[:]
In [8]:
print countries.dtype
print employment.dtype
print np.array([0, 1, 2, 3]).dtype
print np.array([1.0, 1.5, 2.0, 2.5]).dtype
print np.array([True, False, True]).dtype
print np.array(['AL', 'AK', 'AZ', 'AR', 'CA']).dtype
In [9]:
for country in countries:
print 'Examining country {}'.format(country)
In [10]:
for i in range(len(countries)):
country = countries[i]
country_employment = employment[i]
print 'Country {} has employment {}'.format(country,
country_employment)
In [12]:
print employment.mean()
print employment.std()
print employment.max()
print employment.sum()
In [13]:
def max_employment(countries, employment):
'''
Fill in this function to return the name of the country
with the highest employment in the given employment
data, and the employment in that country.
'''
max_value = employment.max() # Replace this with your code
for i in range(len(employment)):
if employment[i] == max_value:
max_country = countries[i] # Replace this with your code
break
return (max_country, max_value)
In [14]:
print max_employment(countries, employment)
In [15]:
def max_employment2(countries, employment):
i = employment.argmax()
return (countries[i], employment[i])
In [17]:
print max_employment2(countries, employment)
In [ ]: