Page 192 - Robotics and AI class 10
P. 192
Sorting the array ARR.sort() a = np.array([12, 4, -10, [-14 -10 -1 4 12
23, 29, 15, -1, 45, 33, 37, 15 23 29 33 37
-14]) # Creating a 1-D 45]
Numpy array [[ -9 5 9 12
print(np.sort(a)) # 18]
Printing the sorted [-10 -5 3 10
numpy array 11]]
# We can also sort array [[ -9 5 3 -5
row wise and column wise! -10]
b = np.array([[-9, 5, 18, [ 10 11 18 9
9, 12], [10, 11, 3, -5, 12]]
-10]]) # Creating a 2-D
Numpy array
print(np.sort(b, axis = 1))
# Axis = 1 performs the
sorting function row-wise
print(np.sort(b, axis = 0))
# Axis = 0 performs the
sorting function columns-
wise
Pandas(PANel Data)
Panda is an open-source Python library used for data manipulation and data analysis. It provides a very strong
feature of using three important data structures - Series (1-dimensional),DataFrame (2-dimensional) and Panel(3-
-dimensional) for smooth processing and analysis of data, regardless of its origin. The data actually need not be
labelled at all to be placed into a Pandas data structure.
Pandas was created by Wes McKinney in 2008 and has derived its name from both "Panel Data", and "Python Data
Analysis" which means using a statistical method of analysing the data taken from the observations about different
cross sections over the period of time.
Pandas libraries are built on NumPy so to work in Pandas the prerequisite is to get familiar with NumPy and install
it. It gives us a single, convenient place to do most of our data analysis and visualisation work.
Data required for Pandas can be taken as :
• Tabular data with heterogeneously-typed columns, as in an SQL table or Excel spreadsheet
• Ordered and unordered (not necessarily fixed-frequency) time series data.
• Arbitrary matrix data (homogeneously typed or heterogeneous) with row and column labels.
• Any other form of observational / statistical data sets.
Installing Pandas
To install Pandas from command line, we need to type in:
pip install pandas
All libraries including NumPy and Pandas can be installed only when Python is already installed on that system.
190 Touchpad Robotics & Artificial Intelligence-X

