0% found this document useful (0 votes)
90 views2 pages

NumPy Arrays

This document contains 12 practice questions on NumPy arrays. The questions cover topics like: - Creating NumPy arrays from lists and ranges - Array slicing and indexing - Concatenating, splitting, stacking arrays - Basic arithmetic operations on arrays like addition, multiplication, division - Logical operations on arrays like extracting subsets
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views2 pages

NumPy Arrays

This document contains 12 practice questions on NumPy arrays. The questions cover topics like: - Creating NumPy arrays from lists and ranges - Array slicing and indexing - Concatenating, splitting, stacking arrays - Basic arithmetic operations on arrays like addition, multiplication, division - Logical operations on arrays like extracting subsets
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Senthil Public School, Dharmapuri

Montessori & CBSE Stream


(Affiliated to CBSE, New Delhi: Affiliation No-1930752)
INFORMATICS PRACTICES
Practise Test 1-NUMPY 14/12/19

1. What are NumPy arrays?


2. What is the relationship between the rank of an array and the shape of the array?
3. Write code to create a 1d ndarray of size 10 with all elements as zero, but the fifth element is 10.
4. Create an ndarray with values ranging from 10 to 49 each spaced with a difference of 3.
5. Create a 4 x 4 ndarray having values ranging from 0 to 15
6. Create a 8 x 8 ndarray and fill it with a checkerboard pattern i.e. 0 and 1 at alternate positions
7. An ndarray X contains the following data
[[0 1 2 3],
[4 5 6 7],
[8 9 10 11],
[12 13 14 15]]
What will be returned by the statements?
a) print(x[0:2, 0:2]) b) print(x[2:0,2:0]) c) print(x[2:0:-1, 2:0:-1])
8. Given following ndarray Ary1
([[1, 2, 3],
4, 5, 6],
7, 8, 9]])
Write array slices in the way so as to a) Extract horizontal row separately b) Vertical column separately
c) Ary1[:2,:3] d) Ary1[:3,::2] e) Ary1[::-1,::-1]
9. Consider following two arrays
Ar1=array([[0, 1, 2], Ar2=array([[10, 11, 12],
[3, 4, 5], [13, 14, 15],
[6, 7, 8]]) [16, 17, 18]])
Write command to concatenate Ar1 and Ar2: a) row-wise b) Column wise
10. Consider the above array, write the output of the given statement.
np.hstack((Ar1,Ar2))
11. Consider the following ndarray Ary1
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
Write code to extract the subset from the ndarray Ary1, containing elements whose square is fully
divisible 4
12. A=([[1,1, 2], B=([[0,9], X=([[1], Y=[1 3 2]
[3, 5, 8], [3, 12], [3],
[13, 21, 34]]) [6, 15]]) [2]])

a) Array A’s product with 2


b) Array B divided by 3
c) Array A’s product with array x
d) Array y’s product with array A
Senthil Public School, Dharmapuri
Montessori & CBSE Stream
(Affiliated to CBSE, New Delhi: Affiliation No-1930752)
INFORMATICS PRACTICES
Practise Test 2-NUMPY 14/12/19

1. If a python list is having 7 integers and a NumPy array is also having 7 integers, then how are these two
data structures similar or different from one another?
2. Given a list L=[3,4,5] and an ndarray N having elements 3,4,5. What will be the result produced by
a) L*3 b) N*3 c) L+L d) N+N
3. Write shapes of following ndarrays:
a) b) 2 c)
1 2 3 4
2 4 6 8 4 5 1 7 8
6
4. Write code to create an ndarray having six zeros in it. Write statements to change 3 rd and 5th elements of
this ndarray to 15 and 25 respectively
5. Create a 3 x 4 two dimensional ndarray from the range of integer 13...24
6. Consider following ndarrays
A=array([10,20,30,40,50,60,70,80,90]) a) B[0:2, 1:3]
B=array([[0,1,2,3], b) A[2:6:3]
[4,5,6,7], c) A[-1:-3]
[8,9,10,11], d) B[::-1]
[12,13,14,15]]) e) B[:3,2:]
f) B[:3,6:2:-1]
7. Predict the output of the following code fragments.
a) x=np.array([1,2,3]) b) grid=np.array([[1,2,3], c) grid=np.array([[1,2,3],
y=np.array([3,2,1]) [4,5,6]]) [4,5,6]])
z=np.concatenate(x,y) G2=np.concatenate([grid,grid]) G2=np.concatenate([grid,grid], axis=1)
print(z) print(G2) print(G2)
8. Predict the output of the following code segments.
a) x=np.array([1,2,3]) b) g=np.array([[9,8,7],
g=np.array([[9,8,7], [6,5,4]])
[6,5,4]]) y= np.array([[99],
R=np.vstack([x,g]) [99]])
Print(R) R=np.hstack([g,y])
print(R)
9. Predict the output of the following code segments
x=[1,2,3,99,99,3,2,1]
x1,x2,x3=np.split(x,[3,5])
print(x1,x2,x3)
10. Write commands to split the following array
array([[0,1,2,3,4,5], array([[0,1], array([[2,3], array([[4,5],
[6,7,8,9,10,11], [6,7], [8,9], [10,11],
[12,13,14,15,16,17]]) [12,13]]) [14,15]]) [16,17]])
11. Write commands to perform following operations on two 4x4 ndarrays namely P and Q
a) Adding 10 to P b) Multiplication of two array P and Q c) Divide all elements of Q by 7
d) Calculate log of all elements of P e) Round all the elements of Q to nearest integer
f) Calculate remainder of all elements of P when divided by 7 g) Calculate square root of all elements of Q

You might also like