p#02 ML 46
p#02 ML 46
import numpy as np
# numpy.linspace()
a_linspace = np.linspace(1, 10, 5)
print("Arrays linspace:",a_linspace )
print("---------------------------------------------------------------
-----------")
# numpy.repeat()
a_repeat = np.repeat(3, 4)
print("Array repeat:",a_repeat)
print("---------------------------------------------------------------
-----------")
# numpy.random()
a_random = np.random.rand(3, 2)
print("Array Random:",a_random)
print("---------------------------------------------------------------
-----------")
# numpy.nan()
a_nan = np.nan
print("Array NaN:",a_nan)
print("---------------------------------------------------------------
-----------")
# numpy.min() and numpy.max()
a = np.array([4, 2, 8, 6, 5])
min_val = np.min(a)
max_val = np.max(a)
print("Minimam Value:",min_val)
print("---------------------------------------------------------------
-----------")
print("Maximam Value:",max_val)
print("---------------------------------------------------------------
-----------")
# numpy.shape()
a_shape = np.array([[1, 2], [3, 4], [5, 6]])
shape = np.shape(a_shape)
print(a)
print("---------------------------------------------------------------
-----------")
print("Array Shape:",a_shape)
print("---------------------------------------------------------------
-----------")
# numpy.argmax()
a_argmax = np.array([10, 30, 20, 40, 50])
argmax_idx = np.argmax(a_argmax)
print("Maximum argument:",a_argmax)
print("---------------------------------------------------------------
-----------")
print("argument index:",argmax_idx)
print("---------------------------------------------------------------
-----------")
# numpy.reshape()
a_reshape = np.arange(12).reshape(3, 4)
print("Array reshape:",a_reshape)
print("---------------------------------------------------------------
-----------")
# numpy.histogram()
hist_values, bin_edges = np.histogram(a_argmax, bins=[0, 20, 40, 60])
print("---------------------------------------------------------------
-----------")
# numpy.mean()
mean_val = np.mean(a_argmax)
print("Array mean value:",mean_val)
print("---------------------------------------------------------------
-----------")
# numpy.sort()
a_sort = np.array([5, 3, 1, 4, 2])
sorted_a = np.sort(a_sort)
print(a_sort)
print("---------------------------------------------------------------
-----------")
print("Sorted Array:",sorted_a)
Shape: (4, 2)
Dimensions: 2
# 3. Create a 5x2 integer array with values ranging from 100 to 200 in
steps of 10:
arr_range = np.arange(100, 200, 10).reshape(5, 2)
print(arr_range)
[[100 110]
[120 130]
[140 150]
[160 170]
[180 190]]
# 4. Return the third column from all rows of the provided array:
a = np.array([[11, 22, 33], [44, 55, 66], [77, 88, 99]])
third_column = a[:, 2]
print(a)
print("---------------------------------------------------------------
-----------")
print("third_column:", third_column)
[[11 22 33]
[44 55 66]
[77 88 99]]
third_column: [33 66 99]
[[ 3 6 9 12]
[15 18 21 24]
[27 30 33 36]
[39 42 45 48]
[51 54 57 60]]
odd_rows_even_columns: [[ 6 12]
[30 36]
[54 60]]
print("result_array:",result_array )
# 9. Print max from axis 0 and min from axis 1 of a 2-D array:
a = np.array([[35, 46, 77], [83, 23, 13], [55, 96, 67]])
max_axis0 = np.max(a, axis=0)
min_axis1 = np.min(a, axis=1)