Define Numpy and its function

Share:

  Numpy and its function👽

Define numpy:

NumPy is a Python library used for working with arrays. It also has functions for working in domain of linear algebra, fourier transform, and matrices. NumPy was created in 2005 by Travis Oliphant. It is an open source project and you can use it freely.



So I have a small codes in which I use numpy :

1 program :

1-First from numpy import random (mean import random from the library of numpy)
2-import numpy as np (so we can use numpy any where as np)
3-take a variable I take (arr) as a variable then np.array[(any number])
4-random .shuffle(arr)[random & shuffle can randomly shuffle the numbers which is in variable (arr) ]
5-print (arr)

Code:

from numpy import random

import numpy as np arr = np.array([1,2,3,4,5,])random.shuffle(arr)

print(arr)

Output:
[4 1 2 3 5] Note:(output is different as every execution)

2 program :

1-import numpy as np (so we can use numpy any where as np)
2-take a variable I take (arr) as a variable then np.array[(any number])
3-Take another variable I take (filter_arr) which is equal to empty set.
4-Now use of For loop if element in arr then enter in for loop
5-In for loop we use if else statement (if element>43:)then filter_arr.append(True)
else: filter_arr.append(True) note:(filter_arr is just a variable you can take any variable)
6-take another variable I take newarr which is equal to variable arr[filter_arr]
7-print(filter_arr)              note:(filter_arr can print true & false here)
8-print(newarr)                 note:(newarr can print numbers here)

Code:

import numpy as np
arr = np.array([22,33,40,43,44,47])
filter_arr = [ ]
for element in arr:
    if element > 43:
        filter_arr.append(True)
    else:
        filter_arr.append(False)
newarr = arr[filter_arr]
print(filter_arr)
print(newarr)


Output:
[False, False, False, False, True, True]
[44 47]