0% found this document useful (0 votes)
17 views1 page

NumPy Arrays and Operations Guide

The document explains the differences between arrays and lists, highlighting that arrays are efficient grids of the same type while lists can hold mixed types. It provides examples of creating various NumPy arrays, including zeros, vowels, ones, and custom arrays, along with operations like addition and matrix multiplication. Additionally, it demonstrates how to handle incompatible shapes during addition and showcases the results of matrix operations.

Uploaded by

sainathmote7121
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)
17 views1 page

NumPy Arrays and Operations Guide

The document explains the differences between arrays and lists, highlighting that arrays are efficient grids of the same type while lists can hold mixed types. It provides examples of creating various NumPy arrays, including zeros, vowels, ones, and custom arrays, along with operations like addition and matrix multiplication. Additionally, it demonstrates how to handle incompatible shapes during addition and showcases the results of matrix operations.

Uploaded by

sainathmote7121
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

Post Lab Questions – NumPy (Experiment 05)

1. What is an array and how is it different from a list?


• An array is a grid of values of the same type, stored efficiently.
• A list is a general-purpose container and can store mixed types.
• Arrays are optimized for numerical operations and memory usage.
• NumPy provides ndarray as the built-in array class.■
2. Create the following NumPy arrays:
a) zeros = [Link](10)
→ [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
b) vowels = [Link](['a','e','i','o','u'])
→ ['a' 'e' 'i' 'o' 'u']
c) ones = [Link]((2,5), dtype=int)
→ [[1 1 1 1 1], [1 1 1 1 1]]
d) myarray1 = [Link]([[2.7,-2,-19],[0,3.4,99.9],[10.6,0,13]])
→ [[ 2.7 -2. -19. ], [ 0. 3.4 99.9], [10.6 0. 13.]]■
3. myarray2 using arange(start=4, step=4, dtype=float).reshape(3,5):
→ [[ 4. 8. 12. 16. 20.]
[24. 28. 32. 36. 40.]
[44. 48. 52. 56. 60.]]■
4. Addition of myarray1 (3x3) and myarray2 (3x5):
→ Direct addition fails (shapes not compatible).
• Workaround: Slice myarray2 to 3x3: myarray2[:, :3]
Result:
[[ 6.7 6. -7. ]
[ 24. 31.4 131.9]
[ 54.6 48. 65. ]]■
5. Matrix multiplication ([Link](myarray2)) gives myarray3:
[[ -873.2 -946.4 -1019.6 -1092.8 -1166. ]
[ 4477.2 4890.4 5303.6 5716.8 6130. ]
[ 614.4 708.8 803.2 897.6 992. ]]■

You might also like