-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_9.py
62 lines (42 loc) · 1.6 KB
/
task_9.py
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
# -*- coding: utf-8 -*-
"""TASK 9.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1gzmhIW6SBvsRPJTqRMuXs2lE4CJcd4XR
1. Create an 4x4 array containing the values ranging from 0 - 15 (use arange function). Then ,
a) split it equally along horizontal.
b) split it as 4 parts vertically.
"""
import numpy as np
array = np.arange(0,16)
newarr = array.reshape(4,4)
print(newarr)
split = np.array_split(newarr,2)
print("\n Equally Splitting Array \n",split)
print("\n Splitting vertically: \n",np.hsplit(newarr,4))
"""2. Create a 3x3 matrix using random module and then,
a) Find the ceil of the matrix.
b) Find the floor of the matrix.
"""
import numpy as np
matrix = np.random.random_sample(size=(3,3))
print(matrix)
ceil = np.ceil(matrix)
print("\n Ceil of the Matrix: \n",ceil)
floor = np.floor(matrix)
print("\n Floor of the Matrix: \n",floor)
"""3. Create a random 1x4 array and print the random array and its shape.
(use the shape function for finding the shape & use the same random we created here for both the below operations.)
a) Squeeze the random array and print the squeezed array and its shape.
b) Expand the random array by one axis and print the expanded array and its shape.
"""
import numpy as np
matrix = np.random.randint(0,10,size=(1,4,2))
print(matrix)
print("The shape of Matrix is: ",np.shape(matrix))
sqz = np.squeeze(matrix)
print("Squeezed: ",sqz)
print("The shape of Matrix is: ",np.shape(sqz))
matrix1 = np.expand_dims(matrix,3)
print("Expanded array: \n",matrix1)
print("Shape is ",matrix1.shape)