-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path1.BasicOfNumpy.py
More file actions
108 lines (66 loc) · 2.5 KB
/
1.BasicOfNumpy.py
File metadata and controls
108 lines (66 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
'''
Created By:Raishankar Chavare
Version:python 3.7
To Install numpy
open command prompt and type:pip install numpy
To import numpy use:import numpy as np
'''
import numpy as np
''' Simple 1 d array using numpy'''
#to create simply numpy array from a normal array use
simple_array=[1,4,2,3,5,4,5,4,5,4,8,4,58,4,8,18]
#simple 1d Array
numpy_array=np.array(simple_array)
#To Print Simple Numpy Array
print('Simple Numpy Array:' , numpy_array)
#dtype, the data type of the array
print(numpy_array.dtype)
#itemsize f the array
print(numpy_array.itemsize)
#To get the Shape of numpy array
print('1d Array Shape:' , numpy_array.shape) #The first paramter is the row and second one is empty because of 1d array
#To findout the max and min number from numpy arry use
print('Maximum Number :', numpy_array.max())#For Max
print('Minimum Number', numpy_array.min())#For Min
#To findout The Index of max number in array user argmax and for min number use argmin
print('')
#To reshaping the 1d array to multidimensssional array use reshape method
mult_array=numpy_array.reshape(4,4)
#Note Before reshaping the array check the element count neither low nor high
#print the ndimenssional aaray
print('Multidimenssional Array:\n',mult_array)
#this will print out the data into the tabular format
##[[ 1 4 2 3]
## [ 5 4 5 4]
## [ 5 4 8 4]
## [58 4 8 10]]
#shape of multidimenssional array (row,column)
print('Shape of Multidimenssional Array:',mult_array.shape)
''' numpy array operation '''
#Create a 1s array
array_1s=np.ones(5)
print('1s array',array_1s)
arrays_2s=np.ones((2,2))
print(arrays_2s)
#create numpy Array using arange function
array_using_range=np.arange(10)
print(array_using_range)
#arange with interval np.arange(start,end,interval)
arange_int=np.arange(0,20,2)
print('nparange with interval: ',arange_int)
#linspace create 10 points from 0 to 5
linspace=np.linspace(0,5,10) #np.linspace(start,end,number of output or points)
print('10 points from 0 to 5 :\n',linspace)
#How to create 2 dimensional square matrix use np.eye(length)
square_matrix=np.eye(4) #Creating identity matrix
print(square_matrix)
#How to create numpy array using rand
#give single elemnt as parameter for 1d array and use 2 parameter for multidimenssional array
random_array=np.random.rand(4)
multi_dimenssion=np.random.rand(4,4)
print(random_array)
print(multi_dimenssion)
#To get the random integer from 1 to 100
print(np.random.randint(1,100))
#To Get the 10 random numbers from 1 to 100
print(np.random.randint(1,100,10))