0% found this document useful (1 vote)
10 views1 page

NumPy Beginner's Guide PDF

The document is a beginner's guide to NumPy, covering essential operations such as array creation, manipulation, and mathematical functions. It includes examples of using Python lists versus NumPy arrays, array indexing, reshaping, and file handling. Additionally, it discusses various array operations, including scalar multiplication, addition, and matrix multiplication.

Uploaded by

i240608
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 (1 vote)
10 views1 page

NumPy Beginner's Guide PDF

The document is a beginner's guide to NumPy, covering essential operations such as array creation, manipulation, and mathematical functions. It includes examples of using Python lists versus NumPy arrays, array indexing, reshaping, and file handling. Additionally, it discusses various array operations, including scalar multiplication, addition, and matrix multiplication.

Uploaded by

i240608
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

Beginner's Guide to NumPy

Numpy
# Python Lists
list1 = list(range(1000000))
list2 = list(range(1000000))

%time result = [x * y for x, y in zip(list1, list2)]

import numpy as np
arr1 = [Link](1000000)
arr2 = [Link](1000000)

%time result = arr1 * arr2

Syntax
# !pip install numpy

import numpy as np

pyl = [1,2,3,4,5,6]
print(type(pyl))
pyl = [Link]([pyl,pyl])
print(type(pyl))

pyl

[Link]

[Link]

[Link] = np.int8
[Link]

[Link] = np.int64

pyl

s = [Link]
type(s)

s[0] = 4

x = [Link](20)
x = [Link](2,10)
x = [Link](4,5)
print(x)
x = x.T
print(x)
x = [Link]()

print(x[5:-1])

y = [Link]([[1,2,3,4,5],
[6,7,8,9,0],
[1,2,3,4,5]])

z = [Link]([[1,2,3,4],
[6,7,8,9],
[1,2,3,4]])

print(f"y = {y}, shape: {[Link]}")


print(f"z = {z}, shape: {[Link]}")

z = [Link]((z,[Link]((3,1))))
z

y*z

x = [Link](5)
x

q = [Link]((2,5)) * 1
# q = q*10
q

w = [Link]((2,5), 10)
w

x = [Link](20)
print(x)
[Link](x, 2)

import numpy as np

arr = [Link]([Link](2,5) * 10, 2)


arr

arr = [Link](0, 100, (5,5))


arr

[Link](1, 22, 3)

[Link](1,22, 10)

[Link]

[Link] * 64

arr = [Link](np.int8)
arr

[Link]

25*16

arr = [Link](np.int16)
arr[3][4] = 67
arr

2**16 / 2

Array operations
# Scaler Multiplication
arr = arr * 2
# arr = [Link](np.int64)
arr

# Scaler Addition
arr = arr + 2
arr

# corresponding Entities Addition


arr1 = arr
print(arr)
print()
print(arr1)

arr1+arr

# corresponding Entities Multiplication


arr1*arr

arr

# Matrix Multiplication
arr = [Link](10).reshape(2,5)
arr1 = [Link](10,20).reshape(2,5)

print(arr)
print()
print(arr1)
print()
print(arr.T @ arr1)
print([Link](arr.T, arr1))

# Indexing
# print(arr[5:])
# arr = [Link]((arr, arr))
print("[x1,x2,x3,x4,x5]")
print(arr)
X_train = arr[:14,:4]
X_test = arr[14:,:4]
Y_train = arr[:14,4:]
Y_test = arr[14:,4:]

print(X_train)
print(X_train.shape)

print(X_test)
X_test.shape

print(Y_train)
print(Y_train.shape)

print(Y_test)
print(Y_test.shape)

# Boolean Indexing
print(arr)
arr[arr%2 == 1]

# Filtering
print(arr)
[Link](arr%2 == 0, 1, 0)

# Aggregations
# arr = arr * 9
# print(arr)
# print([Link]())
# print([Link]())
# print([Link]())
# print([Link]())
# print([Link]())
# print([Link]())
# print([Link]())
# arr = [Link](0, 100, 10)
print(arr)
# print()
arr[[Link]()]

# File Handling in numpy


print([Link])
[Link]('[Link]', arr)
print("File saved Successfully")

arr1 = [Link]('[Link]')
print("File Loaded Successfully")
print(f"File Content: {arr1}")
print([Link])

m = [Link](arr1)
m

# Homework
[Link]()
[Link]()

You might also like