top of page
  • Writer's pictureAdisorn O.

Numpy's Cheat sheet for ML from datacamp.com





# Import the library

import numpy as np


# Create a 1D array

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


# Create a 2D array

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


# Get the shape of an array

a.shape


# Get the number of dimensions of an array

b.ndim


# Get the size (number of elements) of an array

a.size


# Access elements of a 2D array

b[0, 0]


# Perform element-wise addition

np.add(a, a)


# Perform element-wise multiplication

np.multiply(a, a)


# Calculate the dot product of two arrays

np.dot(a, a)


# Calculate the mean of an array

np.mean(a)


# Reshape an array

a.reshape((3, 1))


5 views

Comments


bottom of page