SHELL:
A shell is a type of computer program called a command-line interpreter that lets Linux and Unix
users control their operating systems with command-line interfaces.
Some of the essential basic shell commands in Linux for different operations are:
● File Management -> cp, mv, rm, mkdir
● Navigation -> cd, pwd, ls
● Text Processing -> cat, grep, sort, head
● System Monitoring -> top, ps, df
● Permissions and Ownership -> chmod, chown, chgrp
● Networking – > ping, wget, curl, ssh, scp, ftp
● Compression and Archiving – > tar, gzip, gunzip, zip, unzip
● Package Management – > dnf, yum, apt-get
● Process Management -> kill, killall, bg, killall, kill
The Python shell, also known as the Python interactive interpreter or REPL (Read-Eval-Print
Loop), is a command-line interface that allows you to interact directly with the Python
interpreter, execute code, and see the results immediately.
Jupyter Notebook
Jupyter notebooks are used for all sorts of data science tasks such as exploratory data analysis
(EDA), data cleaning and transformation, data visualization, statistical modeling, machine
learning, and deep learning.
IPython
IPython is an enhanced interactive Python shell that is used inside Jupyter Notebooks. It
provides additional functionality over the standard Python shell.
Magic Commands
Magic commands in IPython start with % (for single-line commands) or %% (for cell-wide
commands).
Commonly Used Magic Commands
Magic Command Description
%ls Lists files in the current directory
%pwd Shows the current working directory
%run script.py Runs an external Python script
%timeit Measures execution time of a
statement statement
Magic Command Description
%history Displays command history
%who Shows all variables in memory
%reset Clears all variables from memory
%matplotlib Displays plots inside Jupyter
inline Notebook
Comparison: Python Shell vs Jupyter Notebook vs IPython
Python Jupyter IPyth
Feature
Shell Notebook on
Interactive Code
✅ Yes ✅ Yes ✅ Yes
Execution
Supports Markdown ❌ No ✅ Yes ❌ No
Inline Visualizations ❌ No ✅ Yes ✅ Yes
Cell Execution ❌ No ✅ Yes ✅ Yes
Magic Commands ❌ No ✅ Yes ✅ Yes
Link : https://jakevdp.github.io/PythonDataScienceHandbook/01.03-magic-commands.html
NumPy Universal functions (ufuncs in short) are simple mathematical functions that operate
on ndarray (N-dimensional array) in an element-wise fashion.
ufunc, or universal functions offer various advantages in NumPy. Some benefits of using ufuncs
are:
1. Vectorized Operations
ufuncs are applied element-wise to all the elements in the ndarray.
Vectorization, in various contexts, refers to transforming data (like text or images) into
numerical vectors, allowing machines to perform mathematical computations on them
efficiently, or converting raster graphics into vector graphics.
ufuncs are more efficient than loops as they are applied simultaneously to all
elements. Vectorization is very useful on large data sets.
2. Type Casting
Type casting means converting the data type of a variable to perform the necessary operation.
ufuncs automatically handle type casting and ensure compatible datatypes for calculations.
This allows code to be concise and reduces the chances of error.
3. Broadcasting
Broadcasting means to perform arithmetic operations on arrays of different size.
ufuncs automatically handle broadcasting and avoids the need for manual array shape
manipulation.
ufunc’s Trigonometric Functions in NumPy
Function Description
compute the sine, cosine, and tangent of
sin, cos, tan
angles
ufunc’s Trigonometric Functions in NumPy
arcsin, arccos, arctan calculate inverse sine, cosine, and tangent
calculate the hypotenuse of the given right
hypot
triangle
sinh, cosh, tanh compute hyperbolic sine, cosine, and tangent
compute inverse hyperbolic sine, cosine, and
arcsinh, arccosh, arctanh
tangent
deg2rad convert degree into radians
rad2deg convert radians into degree
Example: Using Trigonometric Functions
Statistical functions
These functions calculate the mean, median, variance, minimum, etc. of
array elements.
Aggregation:
Function Name NaN-safe Version Description
np.sum np.nansum Compute sum of elements
np.prod np.nanprod Compute product of elements
np.mean np.nanmean Compute mean of elements
np.std np.nanstd Compute standard deviation
np.var np.nanvar Compute variance
np.min np.nanmin Find minimum value
np.max np.nanmax Find maximum value
np.argmin np.nanargmin Find index of minimum value
np.argmax np.nanargmax Find index of maximum value
np.median np.nanmedian Compute median of elements
Compute rank-based statistics of
np.percentile np.nanpercentile
elements
Evaluate whether any elements
np.any N/A
are true
Evaluate whether all elements are
np.all N/A
true
NaN (Not a Number): NaN represents missing or undefined data in
Python.
Examples of Broadcasting
Example 1: Scalar and Array
python
CopyEdit
import numpy as np
arr = np.array([1, 2, 3])
result = arr * 2 # Broadcasting scalar multiplication
print(result) # Output: [2 4 6]
🔹 Why it works? The scalar 2 is "broadcast" to match the shape of arr.
Example 2: Row Vector and Column Vector
python
CopyEdit
a = np.array([[1], [2], [3]]) # Shape (3,1)
b = np.array([10, 20, 30]) # Shape (1,3)
result = a + b # Shape (3,3) after broadcasting
print(result)
Output:
lua
CopyEdit
[[11 21 31]
[12 22 32]
[13 23 33]]
🔹 Why it works?
● a is (3,1), so NumPy expands it horizontally to (3,3).
● b is (1,3), so NumPy expands it vertically to (3,3).
https://jakevdp.github.io/PythonDataScienceHandbook/