Minor Module5
Minor Module5
Minor Module5
Ans: [1,2,3,4,5]
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr)
Ans: [[1 2 3]
[4 5 6]]
3. 3 D array?
arr = np.array([[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]])
Ans: 0, 1, 2, 3
The shape of an array is a tuple of non-negative integers that specify the sizes of each
dimension.
6. How to access array elements?
- By indexing
print(arr[0]) Ans: 1
2. Array of ones
A1=np.ones((2,3))
3. How to create identity matrix?
4. Constant array of size 4x4 with full elements 5
Np.full((4,4),5)
11. What is use of arange()?
1.
Ans:
17. Program to open an existing file, write one more line into it, display.
file = open('myfile.txt', 'a')
file.write('
New line of text')
file.close()
f1=open (‘myfile.txt’, r)
con= f1.read()
print(con)
21. Write a program to create a text file. Read the contents, convert into uppercase letters, write
into another file. Display its contents too..
22. What are different modes for opening a file?
R opening a file for reading
w-> opening a file for writing only ( existing contents will be lost)
a opening a file for writing ( at the end of existing content) – append