Advertisements
Advertisements
प्रश्न
Using the arrays created in Question 4 above, write NumPy commands for the following:
- Find the dimensions, shape, size, data type of the items and itemsize of arrays zeros, vowels, ones, myarray1 and myarray2.
- Reshape the array ones to have all the 10 elements in a single row.
- Display the 2nd and 3rd element of the array vowels.
- Display all elements in the 2nd and 3rd row of the array myarray1.
- Display the elements in the 1st and 2nd column of the array myarray1.
- Display the elements in the 1st column of the 2nd and 3rd row of the array myarray1.
- Reverse the array of vowels.
कोड लेखन
Advertisements
उत्तर
a)
print("zeros:")
print("Dimensions:", zeros.ndim)
print("Shape:", zeros.shape)
print("Size:", zeros.size)
print("Data type:", zeros.dtype)
print("Itemsize:", zeros.itemsize)
print("\nvowels:")
print("Dimensions:", vowels.ndim)
print("Shape:", vowels.shape)
print("Size:", vowels.size)
print("Data type:", vowels.dtype)
print("Itemsize:", vowels.itemsize)
print("\nones:")
print("Dimensions:", ones.ndim)
print("Shape:", ones.shape)
print("Size:", ones.size)
print("Data type:", ones.dtype)
print("Itemsize:", ones.itemsize)
print("\nmyarray1:")
print("Dimensions:", myarray1.ndim)
print("Shape:", myarray1.shape)
print("Size:", myarray1.size)
print("Data type:", myarray1.dtype)
print("Itemsize:", myarray1.itemsize)
print("\nmyarray2:")
print("Dimensions:", myarray2.ndim)
print("Shape:", myarray2.shape)
print("Size:", myarray2.size)
print("Data type:", myarray2.dtype)
print("Itemsize:", myarray2.itemsize)
Output:
zeros:
Dimensions: 2
Shape: (2, 3)
Size: 6
Data type: float64
Itemsize: 8
vowels:
Dimensions: 1
Shape: (5,)
Size: 5
Data type: <U1
Itemsize: 4
ones:
Dimensions: 1
Shape: (10,)
Size: 10
Data type: float64
Itemsize: 8
myarray1:
Dimensions: 2
Shape: (3, 3)
Size: 9
Data type: int64
Itemsize: 8
myarray2:
Dimensions: 2
Shape: (2, 2)
Size: 4
Data type: int64
Itemsize: 8
b)
ones = ones.reshape(1, 10)
print(ones)
Output:
[[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]]
c)
print("\n2nd and 3rd elements of vowels:")
print(vowels[1:3])
Output:
2nd and 3rd elements of vowels:
['e' 'i']
d)
print("\n2nd and 3rd rows of myarray1:")
print(myarray1[1:3])
Output:
2nd and 3rd rows of myarray1:
[[4 |
5 |
5] |
[7 |
8 |
9]] |
e)
print("\n1st and 2nd columns of myarray1:")
print(myarray1[:, 0:2])
Output:
1st and 2nd columns of myarray1:
[1 |
2] |
[4 |
5] |
[7 |
8]] |
f)
print("\n1st column of 2nd and 3rd rows:")
print(myarray1[1:3, 0])
Output:
1st column of 2nd and 3rd rows:
[4 7]
g)
print("\nReverse of vowels:")
print(vowels[::-1])
Output:
Reverse of vowels:
['u' 'o' 'i' 'e' 'a']
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
