Page 447 - AI Ver 3.0 class 10_Flipbook
P. 447
Feature NumPy Array Python List
Accessibility Requires importing NumPy Built-in Python feature (does not require
an additional package)
Mathematical Supports direct mathematical operations Requires looping or applying operations to
Operations on all elements individual elements
Usage Mostly used for scientific computing, Mainly used for data storage and
numerical operations, and data analysis management
Syntax import numpy marks=[34,23,41,42]
marks=numpy.array([34,23,41,42])
Creating an Array using NumPy
Different ways to create an array using NumPy are as follows:
• Creating one dimensional array:
[1]: import numpy
rollno = numpy.array([1, 2, 3])
print(rollno)
[1 2 3]
• Create a sequential 1 D array with values as multiples of 10 from 10 to 100:
[1]: import numpy as np
a = np.arange(10,101,10)
print(a)
[ 10 20 30 40 50 60 70 80 90 100]
• Creating one-dimensional array with 4 random values:
[1]: import numpy as np
a = np.random.random(4)
print(a)
[0.4141628 0.1035279 0.05137008 0.98002355]
• Creating two-dimensional array of 3 rows and 4 columns with random integer values less than 10:
[1]: import numpy as np
a = np.random.randint(10, size=(3,4))
print(a)
[[3 1 4 1]
[7 6 0 1]
[4 2 2 9]]
• Creating two-dimensional array of 3 rows and 4 columns with all ones as value:
[1]: import numpy as np
a = np.ones((3,4))
print(a)
[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]
Advance Python (Practical) 445

