Advertisement
ZergRushA

RT-AI-2

Sep 21st, 2022 (edited)
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. '''
  2. Task 1.3.1
  3.  
  4. import numpy as np
  5.  
  6. checkboard_array = np.zeros((8, 8), dtype=int)
  7. checkboard_array[1::2, ::2] = 1
  8. checkboard_array[::2, 1::2] = 1
  9. print(checkboard_array)
  10.  
  11.  
  12. Task 1.3.2
  13.  
  14. import numpy as np
  15.  
  16. x = np.zeros((5,5))
  17. x += np.arange(5)
  18. print(x)
  19.  
  20.  
  21.  
  22. Task 1.3.3
  23.  
  24. import numpy as np
  25. x = np.random.random((3,3,3))
  26. print(x)
  27.  
  28.  
  29.  
  30. Task 1.3.4
  31.  
  32. import numpy as np
  33.  
  34. x = np.ones((5,5))
  35. x[1:-1, 1:-1] = 0
  36. print(x)
  37.  
  38.  
  39.  
  40. Task  1.3.5
  41.  
  42. import numpy as np
  43. x = np.random.randint(1,20, 10)
  44. print(x)
  45. x[::-1].sort()
  46. print(x)
  47.  
  48.  
  49.  
  50.  
  51. Task 1.3.6
  52.  
  53. import numpy as np
  54. matrix = np.array([np.random.randint(1,10, 5) for _ in range(4)])
  55. print(matrix)
  56. print(f'Matrix shape is: {matrix.shape}',
  57.     f'Matrix ndim is: {matrix.ndim}',
  58.     f'Matrix size is: {matrix.size}', sep='\n')
  59.  
  60.  
  61.  
  62.  
  63. Task  2.3.1
  64.  
  65. import pandas as pd
  66.  
  67. ser_1 = pd.Series([1,3,6,9])
  68. ser_2 = pd.Series([2,5,7,10])
  69.  
  70. print(sum((ser_1-ser_2)**2)**.5)
  71.  
  72.  
  73.  
  74.  
  75. Task 2.3.2
  76.  
  77. import pandas as pd
  78.  
  79. url = r'https://raw.githubusercontent.com/akmand/datasets/main/airlines.csv'
  80.  
  81. dataframe = pd.read_csv(url)
  82.  
  83. print(dataframe.head(10))
  84.  
  85. Task 2.3.3 <-- продолжение 2.3.2
  86.  
  87. print(dataframe.tail(3))
  88.  
  89. print(dataframe.shape)
  90.  
  91. print(dataframe.describe())
  92.  
  93. print(dataframe.iloc[2:6])
  94.  
  95. print(dataframe[dataframe['Airline'] == 'US'].head(2))
  96.  
  97.  
  98.  
  99. #Task 3.3.2
  100.  
  101. import pandas as pd
  102. from sklearn.preprocessing import MinMaxScaler, StandartScaler
  103.  
  104. url = r'https://raw.githubusercontent.com/akmand/datasets/master/iris.csv'
  105.  
  106. dataframe = pd.read_csv(url)
  107.  
  108.  
  109. scaler = MinMaxScaler()
  110.  
  111. std_scaler = StandartScaler()
  112.  
  113.  
  114. sepal_length = min_max_scaler.fit_transform(dataframe['sepal_length_cm'].values.reshape(-1, 1))
  115.  
  116. sepal_width = std_scaler.fit_transform(dataframe['sepal_width_cm'].values.reshape(-1, 1))
  117.  
  118.  
  119. print(sepal_width)
  120.  
  121. print(sepal_length)
  122.  
  123. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement