0% found this document useful (0 votes)
44 views2 pages

Cheat Sheet Numpy

The document provides information about common NumPy functions like np.zeros, np.array, np.linspace, and others. It lists each function, provides an example usage, and describes what the function does. NumPy is a Python library used for working with multi-dimensional arrays and matrices for tasks like machine learning.

Uploaded by

Esther Litan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views2 pages

Cheat Sheet Numpy

The document provides information about common NumPy functions like np.zeros, np.array, np.linspace, and others. It lists each function, provides an example usage, and describes what the function does. NumPy is a Python library used for working with multi-dimensional arrays and matrices for tasks like machine learning.

Uploaded by

Esther Litan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Cheat Sheet : Numpy

Function Example Description

np.zeros np.zeros(10, dtype=np.int16)


Output:
Create a length of n integer array
filled with zeros.
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int16)

Documentation

my_mat = [[1,2,3],[4,5,6],[7,8,9]]
np.array np.array(my_mat)
Creates an array. Output:

3x3 array
Documentation

np.linspace(0, 1, 5)
Output:
np.linspace Create an array of five values
evenly spaced between 0 and 1. array([0, 0.25, 0.5 , 0.75, 1 ])

Documentation

np.random.normal(0,1,(3,3))
Output:
np.random.random
Create a 3x3 array of uniformly
distributed random values between array([[ 0.22032773, -0.53153325, 0.1625384 ],
0 and 1. [ 2.11261584, 0.60143232, -0.2835434 ],
[ 1.38910594, -2.92431186, -1.83753008]])

Documentation

np.reshape arr=np.arange(25)
Creates an array 0 to 25.
Reshaping array to the given arr.reshape(5,5)
dimension. Output:

(5,5)

Documentation

Repetition is the mother of learning, the father of action,


which makes it the architect of accomplishment.” Gencay I from Medium

Zig Ziglar page 1


Function Example Description

np.ones((3,5), dtype = int)


np.ones Output:

Create a n length of an array, filled


array([[1, 1, 1, 1, 1],
with one's.
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]])
Documentation

np.random.randint(0,10,(3,3))
Output:
np.random.randint Create a 3x3 array of random
integers in the interval in given array([[2, 5, 1],
range. [9, 1, 9],
[0, 9, 4]])
Documentation

np.eye(3)
Output:
np.eye
Create a n dimension identity array([[1., 0., 0.],
matrix. [0., 1., 0.],
[0., 0., 1.]])

Documentation

np.arange(25)
Output:
np.arrange
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
Create an array between the given
14, 15, 16,
range, starts from 0.
17, 18, 19, 20, 21, 22, 23, 24])

Documentation

my_mat = [[1,2,3],[4,5,6],[7,8,9]]
np.shape
np.shape(my_matt)
Output:
To find a shape of given array.

(3,3)
Documentation

"Machine learning is the last invention Gencay I from Medium


that humanity will ever need to make." page 2
Nıck Bostrom

You might also like