NumPy Tutorial
NumPy Tutorial
Creating Array :-
[NOTE :- Special Arrays: NumPy offers shortcuts to create arrays filled with zeros
(np.zeros(shape)), ones (np.ones(shape)), or random numbers
(np.random.random(shape))……………………>>>> THIS IS NO NEED AT BSc LAVEL]
2. Array Attributes :-
1
Q) What is the difference between array.shape and array.ndim ?
Ans :- array.ndim gives us the overall dimension and array.shape is gives us the exact shape of the
aray for eg; a (2*3) matrix has shape (2,3) wheras its dimension is 2 .
Eg-1;…
Eg-2;…
2
Let’s try to explain sclicing : basic syntax,
array[start:stop:step] (for 1-D array)
array[row start:row stop:step, columb start:columb stop:step] (For 2-D array)
3
4. Arithmetic Operations :-
4
• Matrix multiplication :-
Method 1
Method 2
5
• Inverse of a Matrix :-
• Setting the Lower Triangle to Zero :- To set the lower triangle of a matrix to zero
in NumPy, you can use the np.triu() function. This function returns the upper
triangle of a matrix, setting all elements below the main diagonal to zero.
6
• Setting the Upper Triangle to Zero :- To set the upper triangle of a matrix to zero
in NumPy, you can use the np.tril() function. This function returns the lower
triangle of a matrix, setting all elements above the main diagonal to zero.
7
Plot using matplot :-
Eg-1:-
Eg-2:-