Menu

NumPy Basics for Machine Learning

NumPy Basics for Machine Learning

NumPy is a Python library for working with arrays and performing fast numerical operations, making it a core machine learning tool.

Creating Arrays

NumPy arrays are similar to lists, but much faster and more efficient for numerical work.

import numpy as np

arr = np.array([1, 2, 3, 4, 5])

print(arr)

Array Operations

You can perform mathematical operations on entire arrays at once, without writing loops.

arr = np.array([1, 2, 3, 4])

print(arr + 10)

print(arr * 2)

Creating Special Arrays

NumPy provides quick ways to create arrays filled with zeros, ones, or a range of numbers.

zeros = np.zeros(5)

ones = np.ones(3)

range_arr = np.arange(1, 10, 2)

Reshaping Arrays

Reshaping lets you change the structure of data, which is often needed before feeding it into a machine learning model.

arr = np.array([1, 2, 3, 4, 5, 6])

reshaped = arr.reshape(2, 3)

print(reshaped)

Basic Statistics with NumPy

NumPy makes it easy to calculate common statistics used throughout machine learning.

data = np.array([10, 20, 30, 40, 50])


print(np.mean(data))

print(np.median(data))

print(np.std(data))

NumPy is the backbone of numerical computing in Python, and libraries like Pandas and Scikit-learn are built directly on top of it.


Machine Learning Tutorial

AP

Abhishek Pati



Learn via Video Course

Artificial Intelligence and Machine Learning Course Logo

Artificial Intelligence and Machine Learning Course

55 hrs



Get in Touch For Details