C 27 Prac 4
C 27 Prac 4
Software Lab
Practical 4
C2-27
A. Write a numpy program to test none of the element of given array is zero.
In [4]: import numpy as np
arr=np.array([1,2,3,4,5])
if(0 in arr):
print("zero exists")
else:
print("no zero")
no zero
B. Write a NumPy program to create a 3x3 matrix with values ranging from 2
to 10.
In [6]: import numpy as np
values = np.arange(2, 11)
matrix = values.reshape(3, 3)
print(matrix)
[[ 2 3 4]
[ 5 6 7]
[ 8 9 10]]
[1, 3, 5, 7, 9]
i) Adding 10 to P
P + 10:
[[11 12 13 14]
[15 16 17 18]
[19 20 21 22]
[23 24 25 26]]
P * Q:
[[16 30 42 52]
[60 66 70 72]
[72 70 66 60]
[52 42 30 16]]
Q / 7:
[[2.28571429 2.14285714 2. 1.85714286]
[1.71428571 1.57142857 1.42857143 1.28571429]
[1.14285714 1. 0.85714286 0.71428571]
[0.57142857 0.42857143 0.28571429 0.14285714]]
P % 7:
[[1 2 3 4]
[5 6 0 1]
[2 3 4 5]
[6 0 1 2]]
Float array:
[1. 2. 3.]
3x4 zero array:
[[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]
Array from tuple:
[[1 2 3]
[4 5 6]]
Random array:
[[0.76029967 0.26013447 0.02800854 0.62677863]
[0.43351522 0.74409579 0.5171985 0.392448 ]
[0.09724443 0.36784024 0.44662988 0.83359967]]
Reshaped array:
[[[ 1 2 3]
[ 4 5 6]]
[[ 7 8 9]
[10 11 12]]]
Sequence array:
[ 0 5 10 15 20 25]
Flattened array:
[ 1 2 3 4 5 6 7 8 9 10 11 12]
Complex array:
[[1.+2.j 1.+2.j 1.+2.j 1.+2.j]
[1.+2.j 1.+2.j 1.+2.j 1.+2.j]
[1.+2.j 1.+2.j 1.+2.j 1.+2.j]]
In [ ]: