0% found this document useful (0 votes)
6 views8 pages

NumPy Tutorial

The document provides an overview of creating and manipulating arrays using NumPy, including special arrays filled with zeros, ones, or random numbers. It explains array attributes such as shape and dimensions, indexing and slicing techniques for 1D and 2D arrays, and basic arithmetic operations like matrix multiplication and setting triangular matrix elements to zero. Additionally, it mentions plotting with Matplotlib but does not provide detailed examples.

Uploaded by

sayan.chem228
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views8 pages

NumPy Tutorial

The document provides an overview of creating and manipulating arrays using NumPy, including special arrays filled with zeros, ones, or random numbers. It explains array attributes such as shape and dimensions, indexing and slicing techniques for 1D and 2D arrays, and basic arithmetic operations like matrix multiplication and setting triangular matrix elements to zero. Additionally, it mentions plotting with Matplotlib but does not provide detailed examples.

Uploaded by

sayan.chem228
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

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;…

3. Array Indexing and Slicing :-


• 1D Indexing: Access elements using indices like array_1d[0].
• 2D Indexing: For a 2D array, use [row, column], like array_2d[0, 1].
• Slicing: Extract subarrays using slicing array[start:stop:step]

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:-

You might also like