NumPy: Transforming Data
✕Data Cleaning
Question 1 of 4
- Write a function
clean_outlierthat takes 1D array, replaces outliers with median & return clean data. (Outliers: data below Q1 - 1.5 * IQR or above Q3 + 1.5 * IQR). - Write a function
clean_outlier_stdthat implements similar task but different outlier definition. (data below mean - 2 * std or above mean + 2 * std). - You have sensor recording data over time. It records invalid value as
-1. Write a functionclean_invalidthat takes 1D array, replace-1with surrounding mean & return clean data. - Write function
fix_invalid_datathat takes 2D NumPy array. Array contains invalid value represented as-999. Function has to substitute invalid value with mean of data. Optionally function should have axis argument. Ifaxis=0, replacement has to be done bycolumn mean. Ifaxis=1, replace byrow meanelseoverall mean. [Hint:np.apply_along_axis(fn, axis, data)]
- Write a function
Conditional (where, select)
Question 2 of 4
- Write a function
incrment_salarythat takes salary_array and returns increased salary. Hike Rule:<1000 => 20%,1000-5000 => 10%,>5000 => 5%. (use:np.select) - Write a function
categorize_agethat takes age_array and categorizes it asChild,Teen,Adult,Seniordepending on age range. (use:np.select) - Assign temp_data as
[15, 22, 30, 5, 18, 25]. Generate new arraytemp_categorythat has elementsbelow_avgandabove_avg. (use:np.where) - Assign player_name as
["Player1", "Player2", "Player3", "Player4"], player_score as[85, 92, 78, 90]. Find the name of players with score above90and store astop_players.
- Write a function
Transforming Arrays
Question 3 of 4
- Create
4x4array with values randomly from0-255. Reshape it to3x3withnp.resize. - Create
6x6array with values randomly from0-255. Reshape it to4x9withnp.shape. - Create
4x8array from normal distribution (u=40, sd=10). Transpose this and print. - Create
3x3array with random value from0-255. Convert it to4x4such that excess element to left and top are filled with zero. - Create
4x4array with random values from0-20. Convert it into 1D usingreshape,resize,flattenandravel. - Practice the questions from Hacker Rank.
- Create
Merging Arrays
Question 4 of 4
- Create
4x3array with random values from0-60. Another2x3array with random values from10-80. Merge them vertically usingconcatandvstack. - Create
3x4array with random values from60-80. Another3x2array with random values from20-90. Merge them horizontally usingconcatandhstack. - Ram and Shyam are doing survey on KTM & POKHARA city for pollution.
CO2&Tempreading recorded by them are[[.5, 22], [.3, 20], [.7, 25]],[[.3, 20], [.2, 23], [.24, 21]]. - What ismax&minvalue of CO2 and Temperature? (considering both cities) - DisplayCO2&Tempreadings for day - 2? (both city) - Store
brnd_sz_aras[['Adidas', 'S'], ['Nike', 'L'], ['Adidas', 'M'], ['Nike', 'S']. Storeprc_wrnty_aras[[150, 1], [120, 0.6], [200, 1.2], [180, 0.9]]. Create array tshirt_info by combining feature from these.
- Create
