SlideShare a Scribd company logo
1 | P a g e
############################Python Numpy Source Codes######################
Note: Loops are slower than numpy arrays!
###############
import numpy as np
l=[1,2]
nplist = np.array(l)
print(nplist)
RESULT:
[1 2]
##################
import numpy as np
L=[1,2,3]
NA = np.array(L)
for i in L:
print(i)
RESULT:
1
2
3
####################
import numpy as np
L=[1,2,3]
NA = np.array(L)
for i in NA:
print(i)
RESULT:
1
2
3
########################
import numpy as np
L=[1,2,3]
L1=L+[4] #append
print(L1)
RESULT:
[1, 2, 3, 4]
2 | P a g e
#########################
import numpy as np
import numpy as np
L=[1,2,3,4]
L.append(5)
print(L)
RESULT:
[1, 2, 3, 4, 5]
#########################
import numpy as np
L=[1,2,3]
NA = np.array(L)
print(NA) #NA=[1 2 3]
NA1 = NA + [4] #vector addition, 4 is added to each element
print(NA1) #NA1=[5 6 7]
##########################
import numpy as np
L=[1,2,3]
NA = np.array(L)
print(NA) #NA=[1 2 3]
NA.append(8)
RESULT:
AttributeError: 'numpy.ndarray' object has no attribute 'append'
#############################
import numpy as np
L=[1,2,3]
NA = np.array(L)#[1 2 3]
NA2 = NA + NA
print(NA2) #Vector addition:[1 2 3]+[1 2 3]=[2 4 6]
L2 = L + L
print(L2) #List addition is simply concatenation [1, 2, 3, 1, 2, 3]
##########vector addition in list#########
L= [1,2,3]
L3 = []
for i in L:
L3.append(i+i)
print(L3) #[2,4,6]
3 | P a g e
#########vector multipication######
import numpy as np
L=[1,2,3]
NA = np.array(L)#[1 2 3]
print(2*NA) # vector multiplication [2 4 6]
print(2*L) #list multiplication :[1, 2, 3, 1, 2, 3]
#############Square operation########
import numpy as np
L=[1,2,3]
NA = np.array(L)#[1 2 3]
print(NA**2) # Square operation: [1 4 9]
print(L**2) #TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
############List Square operation#######
L= [1,2,3]
L3 = []
for i in L:
L3=i*i
print(L3) #[1,4,9]
############Square root operation######
import numpy as np
L=[1,2,3]
NA = np.array(L)#[1 2 3]
print(np.sqrt(NA)) # Square operation: [1. 1.41421356 1.73205081]
############log operation############
import numpy as np
L=[1,2,3]
NA = np.array(L)#[1 2 3]
print(np.log(NA))# log operation:[0. 0.69314718 1.09861229]
###########exponential operation######
import numpy as np
L=[1,2,3]
NA = np.array(L)#[1 2 3]
print(np.exp(NA))# exponential operation:[ 2.71828183 7.3890561 20.08553692]
#############################
import numpy as np
a=np.array([1,2,3])
b=np.array([[1,2], [3,4], [5,6]])
print(a[0]) #a[0]=1
print(b[0]) #b[0]=[1 2]
4 | P a g e
print(b[0][0])# b[0][0]= 1
print(b[0][1])# b[0][1]= 2
M=np.matrix([[1,2], [3,4], [5,6]])
print(M) #Matrix form
print(M[0][0]) #M[0][0]=[[1 2]]
print(M[0,0]) #M[0,0]=1
############################
import numpy as np
a=np.array([1,2,3])
b=np.array([[1,2], [3,4], [5,6]])
print(b)
RESULT:
[[1 2]
[3 4]
[5 6]]
#####################Transpose operation##############
import numpy as np
a=np.array([1,2,3])
b=np.array([[1,2], [3,4], [5,6]])
print(b.T) # Transpose operation
RESULT:
[[1 3 5]
[2 4 6]]
#############No. of rows and cols ##############
import numpy as np
b=np.array([[1,2], [3,4], [5,6]])
print(b.shape) # rows x cols= (3, 2)
c=b.T
print(c.shape) # rows x cols=(2, 3)
###############To check dimension of array#############
import numpy as np
a=np.array([1,2,3])
print(a.ndim) #a is 1 dimensional array
b=np.array([[1,2], [3,4], [5,6]])
print(b.ndim) #b is 2 dimensional array
c=b.T
print(c.ndim) #c is 2 dimensional array
5 | P a g e
##############To check total no. of elements in an array###########
import numpy as np
a=np.array([1,2,3])
print(a.size) #a has 3 elements
b=np.array([[1,2], [3,4], [5,6]])
print(b.size) #b has 6 elements
c=b.T
print(c.size) #c has 6 elements
##############To check data type of an array###########
import numpy as np
a=np.array([1,2,3])
print(a.dtype) #int32
b=np.array([[1,2], [3,4], [5,6]])
print(b.dtype) #int32
c=b.T
print(c.dtype) #int32
##########data type conversion########
import numpy as np
a=np.array([1,2,3])
b=np.array([1,2,3], dtype=np.float32)
print(b) #[1. 2. 3.]
##########Check each elemenet size#########
import numpy as np
a=np.array([1,2,3])
print(a.itemsize) #4 bytes
b=np.array([1,2,3], dtype=np.float64)
print(b.itemsize) #8 bytes
##########Check minimum and maximum elemenet #######
import numpy as np
a=np.array([1,2,3])
print(a.min()) #minimum element is 1
print(a.max()) #maximum element is 3
##########Check sum of elemenets#######
import numpy as np
a=np.array([1,2,3])
print(a.sum()) #sum of all elements is 6
6 | P a g e
##########axis sum##########
import numpy as np
b=np.array([[1,2], [3,4], [5,6]])
print(b.sum(axis=0)) #1+3+5=9, 2+4+6=12,
print(b.sum(axis=1)) #1+2=3, 3+4=7, 5+6=11
###########
import numpy as np
a=np.zeros((2,3)) #2 rows and 3 cols
print(a)
RESULT:
[[0. 0. 0.]
[0. 0. 0.]]
###############
import numpy as np
b=np.ones((3,2))
print(b)
RESULT:
[[1. 1.]
[1. 1.]
[1. 1.]]
###########
import numpy as np
b=np.ones((3,2), dtype=np.int16)
print(b)
RESULT:
[[1 1]
[1 1]
[1 1]]
##########Crete random data###########
import numpy as np
print(np.empty((3,3)))
RESULT:
[[0.00000000e+000 0.00000000e+000 0.00000000e+000]
[0.00000000e+000 0.00000000e+000 1.91697471e-321]
[1.93101617e-312 1.93101617e-312 0.00000000e+000]]
7 | P a g e
#######################
import numpy as np
print(np.empty([3,3]))
RESULT:
[[6.23042070e-307 3.56043053e-307 1.60219306e-306]
[7.56571288e-307 1.89146896e-307 1.37961302e-306]
[1.05699242e-307 8.01097889e-307 0.00000000e+000]]
########################
import numpy as np
print(np.empty([3,3], dtype=np.int16))
RESULT:
After first execution:
[[4 0 0]
[0 4 0]
[0 0 0]]
After second execution:
[[0 0 0]
[0 0 0]
[0 0 0]]
#################
import numpy as np
print(np.arange(0,5)) #[0 1 2 3 4]
print(np.arange(0,5, 0.5)) #[0. 0.5 1. 1.5 2. 2.5 3. 3.5 4. 4.5]
##################
import numpy as np
print(np.linspace(0,5)) #Linearly space the value in range 0 to 5
#By default it takes 50 values
RESULT:
[0. 0.10204082 0.20408163 0.30612245 0.40816327 0.51020408
0.6122449 0.71428571 0.81632653 0.91836735 1.02040816 1.12244898
1.2244898 1.32653061 1.42857143 1.53061224 1.63265306 1.73469388
1.83673469 1.93877551 2.04081633 2.14285714 2.24489796 2.34693878
2.44897959 2.55102041 2.65306122 2.75510204 2.85714286 2.95918367
3.06122449 3.16326531 3.26530612 3.36734694 3.46938776 3.57142857
3.67346939 3.7755102 3.87755102 3.97959184 4.08163265 4.18367347
4.28571429 4.3877551 4.48979592 4.59183673 4.69387755 4.79591837
4.89795918 5.]
8 | P a g e
##############
import numpy as np
print(np.linspace(1,5,10))
RESULT:
[1. 1.44444444 1.88888889 2.33333333 2.77777778 3.22222222
3.66666667 4.11111111 4.55555556 5. ]
############Create random numbers#############
import numpy as np
print(np.random.random((2,3))) #dimension is 2 rows X 3 cols
RESULT:
[[0.13945931 0.16273058 0.56452845]
[0.61644482 0.18447141 0.17318377]]
############Reshaping array dimension#############
import numpy as np
c=np.zeros((2,3))
print(c)
print(c.reshape(6,1))
print(c.reshape(3,2))
############Reshaping array dimension#############
import numpy as np
c=np.zeros((2,5))
print(c)
print(c.reshape(5,-1)) # here 5 rows are created while cols created automatically by using '-1'
#############Stack vertically####################
import numpy as np
c=np.zeros((2,5))
d=np.ones((1,5))
e=np.vstack((c,d))
print(e)
RESULT;
[[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]
[1. 1. 1. 1. 1.]]
#############Stack vertically####################
9 | P a g e
import numpy as np
c=np.zeros((2,5))
d=np.ones((1,5))
e=np.vstack((d,c))
print(e)
RESULT:
[[1. 1. 1. 1. 1.]
[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]]
#############Stack horizontally####################
import numpy as np
c=np.zeros((1,5))
d=np.ones((1,5))
e=np.hstack((d,c))
print(e)
RESULT:
[[1. 1. 1. 1. 1. 0. 0. 0. 0. 0.]]
#########Vertical array Split###########
import numpy as np
b=np.array([[1,2], [3,4], [5,6]])
print(b)
e=np.vsplit(b , 3) #vertical split in 3 parts
print(e)
RESULT:
[[1 2]
[3 4]
[5 6]]
[array([[1, 2]]), array([[3, 4]]), array([[5, 6]])]
#########Horizontal array Split###########
import numpy as np
b=np.array([[1,2], [3,4], [5,6]])
print(b)
e=np.hsplit(b , 2)
print(e)
10 | P a g e
RESULT:
[[1 2]
[3 4]
[5 6]]
[array([[1],
[3],
[5]]), array([[2],
[4],
[6]])]

More Related Content

What's hot (20)

最新の HPC 技術を生かした AI・ビッグデータインフラの東工大 TSUBAME3.0 及び産総研 ABCI
最新の HPC 技術を生かした AI・ビッグデータインフラの東工大 TSUBAME3.0 及び産総研 ABCI最新の HPC 技術を生かした AI・ビッグデータインフラの東工大 TSUBAME3.0 及び産総研 ABCI
最新の HPC 技術を生かした AI・ビッグデータインフラの東工大 TSUBAME3.0 及び産総研 ABCI
NVIDIA Japan
 
Power BI 初心者さんのDAX・メジャー「モヤモヤ」晴れるまで
Power BI 初心者さんのDAX・メジャー「モヤモヤ」晴れるまでPower BI 初心者さんのDAX・メジャー「モヤモヤ」晴れるまで
Power BI 初心者さんのDAX・メジャー「モヤモヤ」晴れるまで
陽子 小室
 
Efficient Neural Architecture Search via Parameters Sharing @ ICML2018読み会
Efficient Neural Architecture Search via Parameters Sharing @ ICML2018読み会Efficient Neural Architecture Search via Parameters Sharing @ ICML2018読み会
Efficient Neural Architecture Search via Parameters Sharing @ ICML2018読み会
tomohiro kato
 
CANVA AI プレゼンテーション資料.pdf
CANVA AI プレゼンテーション資料.pdfCANVA AI プレゼンテーション資料.pdf
CANVA AI プレゼンテーション資料.pdf
ShinYoshimura2
 
密度比推定による時系列データの異常検知
密度比推定による時系列データの異常検知密度比推定による時系列データの異常検知
密度比推定による時系列データの異常検知
- Core Concept Technologies
 
全部Excelでやろうとして後悔するデータ分析
全部Excelでやろうとして後悔するデータ分析全部Excelでやろうとして後悔するデータ分析
全部Excelでやろうとして後悔するデータ分析
__john_smith__
 
「顧客の声を聞かない」とはどういうことか
「顧客の声を聞かない」とはどういうことか「顧客の声を聞かない」とはどういうことか
「顧客の声を聞かない」とはどういうことか
Yoshiki Hayama
 
音声合成の基礎
音声合成の基礎音声合成の基礎
音声合成の基礎
Akinori Ito
 
固有顔による生体認証
固有顔による生体認証固有顔による生体認証
固有顔による生体認証
Hiroyuki Kuromiya
 
深層学習による自然言語処理入門: word2vecからBERT, GPT-3まで
深層学習による自然言語処理入門: word2vecからBERT, GPT-3まで深層学習による自然言語処理入門: word2vecからBERT, GPT-3まで
深層学習による自然言語処理入門: word2vecからBERT, GPT-3まで
Yahoo!デベロッパーネットワーク
 
10分でわかったつもりになるlean start up ~リーンスタートアップって何ですか?~
10分でわかったつもりになるlean start up ~リーンスタートアップって何ですか?~10分でわかったつもりになるlean start up ~リーンスタートアップって何ですか?~
10分でわかったつもりになるlean start up ~リーンスタートアップって何ですか?~
圭 進藤
 
KubernetesでGPUクラスタを管理したい
KubernetesでGPUクラスタを管理したいKubernetesでGPUクラスタを管理したい
KubernetesでGPUクラスタを管理したい
Yuji Oshima
 
分散学習のあれこれ~データパラレルからモデルパラレルまで~
分散学習のあれこれ~データパラレルからモデルパラレルまで~分散学習のあれこれ~データパラレルからモデルパラレルまで~
分散学習のあれこれ~データパラレルからモデルパラレルまで~
Hideki Tsunashima
 
総和伝搬法を用いた分散近似メッセージ伝搬アルゴリズム
総和伝搬法を用いた分散近似メッセージ伝搬アルゴリズム総和伝搬法を用いた分散近似メッセージ伝搬アルゴリズム
総和伝搬法を用いた分散近似メッセージ伝搬アルゴリズム
Ryo Hayakawa
 
2019年度チュートリアルBPE
2019年度チュートリアルBPE2019年度チュートリアルBPE
2019年度チュートリアルBPE
広樹 本間
 
ElixirでFPGAハードウェアが作れちゃう,かも!!?
ElixirでFPGAハードウェアが作れちゃう,かも!!?ElixirでFPGAハードウェアが作れちゃう,かも!!?
ElixirでFPGAハードウェアが作れちゃう,かも!!?
Hideki Takase
 
[論文紹介] 機械学習システムの安全性における未解決な問題
[論文紹介] 機械学習システムの安全性における未解決な問題[論文紹介] 機械学習システムの安全性における未解決な問題
[論文紹介] 機械学習システムの安全性における未解決な問題
tmtm otm
 
疾患を意識した関節所見の取り方
疾患を意識した関節所見の取り方疾患を意識した関節所見の取り方
疾患を意識した関節所見の取り方
帝京大学ちば総合医療センター
 
感度・特異度・陽性的中率・尤度比とベイズの定理
感度・特異度・陽性的中率・尤度比とベイズの定理感度・特異度・陽性的中率・尤度比とベイズの定理
感度・特異度・陽性的中率・尤度比とベイズの定理
TakahiroKinoshita3
 
CV分野におけるサーベイ方法
CV分野におけるサーベイ方法CV分野におけるサーベイ方法
CV分野におけるサーベイ方法
Hirokatsu Kataoka
 
最新の HPC 技術を生かした AI・ビッグデータインフラの東工大 TSUBAME3.0 及び産総研 ABCI
最新の HPC 技術を生かした AI・ビッグデータインフラの東工大 TSUBAME3.0 及び産総研 ABCI最新の HPC 技術を生かした AI・ビッグデータインフラの東工大 TSUBAME3.0 及び産総研 ABCI
最新の HPC 技術を生かした AI・ビッグデータインフラの東工大 TSUBAME3.0 及び産総研 ABCI
NVIDIA Japan
 
Power BI 初心者さんのDAX・メジャー「モヤモヤ」晴れるまで
Power BI 初心者さんのDAX・メジャー「モヤモヤ」晴れるまでPower BI 初心者さんのDAX・メジャー「モヤモヤ」晴れるまで
Power BI 初心者さんのDAX・メジャー「モヤモヤ」晴れるまで
陽子 小室
 
Efficient Neural Architecture Search via Parameters Sharing @ ICML2018読み会
Efficient Neural Architecture Search via Parameters Sharing @ ICML2018読み会Efficient Neural Architecture Search via Parameters Sharing @ ICML2018読み会
Efficient Neural Architecture Search via Parameters Sharing @ ICML2018読み会
tomohiro kato
 
CANVA AI プレゼンテーション資料.pdf
CANVA AI プレゼンテーション資料.pdfCANVA AI プレゼンテーション資料.pdf
CANVA AI プレゼンテーション資料.pdf
ShinYoshimura2
 
密度比推定による時系列データの異常検知
密度比推定による時系列データの異常検知密度比推定による時系列データの異常検知
密度比推定による時系列データの異常検知
- Core Concept Technologies
 
全部Excelでやろうとして後悔するデータ分析
全部Excelでやろうとして後悔するデータ分析全部Excelでやろうとして後悔するデータ分析
全部Excelでやろうとして後悔するデータ分析
__john_smith__
 
「顧客の声を聞かない」とはどういうことか
「顧客の声を聞かない」とはどういうことか「顧客の声を聞かない」とはどういうことか
「顧客の声を聞かない」とはどういうことか
Yoshiki Hayama
 
音声合成の基礎
音声合成の基礎音声合成の基礎
音声合成の基礎
Akinori Ito
 
固有顔による生体認証
固有顔による生体認証固有顔による生体認証
固有顔による生体認証
Hiroyuki Kuromiya
 
深層学習による自然言語処理入門: word2vecからBERT, GPT-3まで
深層学習による自然言語処理入門: word2vecからBERT, GPT-3まで深層学習による自然言語処理入門: word2vecからBERT, GPT-3まで
深層学習による自然言語処理入門: word2vecからBERT, GPT-3まで
Yahoo!デベロッパーネットワーク
 
10分でわかったつもりになるlean start up ~リーンスタートアップって何ですか?~
10分でわかったつもりになるlean start up ~リーンスタートアップって何ですか?~10分でわかったつもりになるlean start up ~リーンスタートアップって何ですか?~
10分でわかったつもりになるlean start up ~リーンスタートアップって何ですか?~
圭 進藤
 
KubernetesでGPUクラスタを管理したい
KubernetesでGPUクラスタを管理したいKubernetesでGPUクラスタを管理したい
KubernetesでGPUクラスタを管理したい
Yuji Oshima
 
分散学習のあれこれ~データパラレルからモデルパラレルまで~
分散学習のあれこれ~データパラレルからモデルパラレルまで~分散学習のあれこれ~データパラレルからモデルパラレルまで~
分散学習のあれこれ~データパラレルからモデルパラレルまで~
Hideki Tsunashima
 
総和伝搬法を用いた分散近似メッセージ伝搬アルゴリズム
総和伝搬法を用いた分散近似メッセージ伝搬アルゴリズム総和伝搬法を用いた分散近似メッセージ伝搬アルゴリズム
総和伝搬法を用いた分散近似メッセージ伝搬アルゴリズム
Ryo Hayakawa
 
2019年度チュートリアルBPE
2019年度チュートリアルBPE2019年度チュートリアルBPE
2019年度チュートリアルBPE
広樹 本間
 
ElixirでFPGAハードウェアが作れちゃう,かも!!?
ElixirでFPGAハードウェアが作れちゃう,かも!!?ElixirでFPGAハードウェアが作れちゃう,かも!!?
ElixirでFPGAハードウェアが作れちゃう,かも!!?
Hideki Takase
 
[論文紹介] 機械学習システムの安全性における未解決な問題
[論文紹介] 機械学習システムの安全性における未解決な問題[論文紹介] 機械学習システムの安全性における未解決な問題
[論文紹介] 機械学習システムの安全性における未解決な問題
tmtm otm
 
感度・特異度・陽性的中率・尤度比とベイズの定理
感度・特異度・陽性的中率・尤度比とベイズの定理感度・特異度・陽性的中率・尤度比とベイズの定理
感度・特異度・陽性的中率・尤度比とベイズの定理
TakahiroKinoshita3
 
CV分野におけるサーベイ方法
CV分野におけるサーベイ方法CV分野におけるサーベイ方法
CV分野におけるサーベイ方法
Hirokatsu Kataoka
 

Similar to Python Numpy Source Codes (20)

NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
tahirnaquash2
 
NUMPY LIBRARY study materials PPT 2.pptx
NUMPY LIBRARY study materials PPT 2.pptxNUMPY LIBRARY study materials PPT 2.pptx
NUMPY LIBRARY study materials PPT 2.pptx
CHETHANKUMAR274045
 
NUMPY
NUMPY NUMPY
NUMPY
Global Academy of Technology
 
numpy code and examples with attributes.pptx
numpy code and examples with attributes.pptxnumpy code and examples with attributes.pptx
numpy code and examples with attributes.pptx
swathis752031
 
Concept of Data science and Numpy concept
Concept of Data science and Numpy conceptConcept of Data science and Numpy concept
Concept of Data science and Numpy concept
Deena38
 
Data Preprocessing Introduction for Machine Learning
Data Preprocessing Introduction for Machine LearningData Preprocessing Introduction for Machine Learning
Data Preprocessing Introduction for Machine Learning
sonali sonavane
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
UmarMustafa13
 
CAP776Numpy (2).ppt
CAP776Numpy (2).pptCAP776Numpy (2).ppt
CAP776Numpy (2).ppt
ChhaviCoachingCenter
 
CAP776Numpy.ppt
CAP776Numpy.pptCAP776Numpy.ppt
CAP776Numpy.ppt
kdr52121
 
python_programming_NumPy_Pandas_Notes.pptx
python_programming_NumPy_Pandas_Notes.pptxpython_programming_NumPy_Pandas_Notes.pptx
python_programming_NumPy_Pandas_Notes.pptx
sunilsoni446112
 
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
DineshThallapelly
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
Zahid Hasan
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
Nishant Upadhyay
 
Python_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdfPython_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdf
AnonymousUser67
 
Numpy cheat-sheet
Numpy cheat-sheetNumpy cheat-sheet
Numpy cheat-sheet
Arief Kurniawan
 
Python for Data Science and Scientific Computing
Python for Data Science and Scientific ComputingPython for Data Science and Scientific Computing
Python for Data Science and Scientific Computing
Abhijit Kar Gupta
 
@Computeronic_NumPy EMERSON EDUARDO RODRIGUES.pdf
@Computeronic_NumPy EMERSON EDUARDO RODRIGUES.pdf@Computeronic_NumPy EMERSON EDUARDO RODRIGUES.pdf
@Computeronic_NumPy EMERSON EDUARDO RODRIGUES.pdf
EMERSON EDUARDO RODRIGUES
 
Lecture 2 _Foundions foundions NumPyI.pptx
Lecture 2 _Foundions foundions NumPyI.pptxLecture 2 _Foundions foundions NumPyI.pptx
Lecture 2 _Foundions foundions NumPyI.pptx
disserdekabrcha
 
Numpy questions with answers and practice
Numpy questions with answers and practiceNumpy questions with answers and practice
Numpy questions with answers and practice
basicinfohub67
 
Numpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptxNumpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptx
VGaneshKarthikeyan
 
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
tahirnaquash2
 
NUMPY LIBRARY study materials PPT 2.pptx
NUMPY LIBRARY study materials PPT 2.pptxNUMPY LIBRARY study materials PPT 2.pptx
NUMPY LIBRARY study materials PPT 2.pptx
CHETHANKUMAR274045
 
numpy code and examples with attributes.pptx
numpy code and examples with attributes.pptxnumpy code and examples with attributes.pptx
numpy code and examples with attributes.pptx
swathis752031
 
Concept of Data science and Numpy concept
Concept of Data science and Numpy conceptConcept of Data science and Numpy concept
Concept of Data science and Numpy concept
Deena38
 
Data Preprocessing Introduction for Machine Learning
Data Preprocessing Introduction for Machine LearningData Preprocessing Introduction for Machine Learning
Data Preprocessing Introduction for Machine Learning
sonali sonavane
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
UmarMustafa13
 
CAP776Numpy.ppt
CAP776Numpy.pptCAP776Numpy.ppt
CAP776Numpy.ppt
kdr52121
 
python_programming_NumPy_Pandas_Notes.pptx
python_programming_NumPy_Pandas_Notes.pptxpython_programming_NumPy_Pandas_Notes.pptx
python_programming_NumPy_Pandas_Notes.pptx
sunilsoni446112
 
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
DineshThallapelly
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
Zahid Hasan
 
Python_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdfPython_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdf
AnonymousUser67
 
Python for Data Science and Scientific Computing
Python for Data Science and Scientific ComputingPython for Data Science and Scientific Computing
Python for Data Science and Scientific Computing
Abhijit Kar Gupta
 
@Computeronic_NumPy EMERSON EDUARDO RODRIGUES.pdf
@Computeronic_NumPy EMERSON EDUARDO RODRIGUES.pdf@Computeronic_NumPy EMERSON EDUARDO RODRIGUES.pdf
@Computeronic_NumPy EMERSON EDUARDO RODRIGUES.pdf
EMERSON EDUARDO RODRIGUES
 
Lecture 2 _Foundions foundions NumPyI.pptx
Lecture 2 _Foundions foundions NumPyI.pptxLecture 2 _Foundions foundions NumPyI.pptx
Lecture 2 _Foundions foundions NumPyI.pptx
disserdekabrcha
 
Numpy questions with answers and practice
Numpy questions with answers and practiceNumpy questions with answers and practice
Numpy questions with answers and practice
basicinfohub67
 
Numpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptxNumpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptx
VGaneshKarthikeyan
 
Ad

More from Amarjeetsingh Thakur (20)

“Introduction to MATLAB & SIMULINK”
“Introduction to MATLAB  & SIMULINK”“Introduction to MATLAB  & SIMULINK”
“Introduction to MATLAB & SIMULINK”
Amarjeetsingh Thakur
 
Python code for servo control using Raspberry Pi
Python code for servo control using Raspberry PiPython code for servo control using Raspberry Pi
Python code for servo control using Raspberry Pi
Amarjeetsingh Thakur
 
Python code for Push button using Raspberry Pi
Python code for Push button using Raspberry PiPython code for Push button using Raspberry Pi
Python code for Push button using Raspberry Pi
Amarjeetsingh Thakur
 
Python code for Buzzer Control using Raspberry Pi
Python code for Buzzer Control using Raspberry PiPython code for Buzzer Control using Raspberry Pi
Python code for Buzzer Control using Raspberry Pi
Amarjeetsingh Thakur
 
Arduino programming part 2
Arduino programming part 2Arduino programming part 2
Arduino programming part 2
Amarjeetsingh Thakur
 
Arduino programming part1
Arduino programming part1Arduino programming part1
Arduino programming part1
Amarjeetsingh Thakur
 
Python openCV codes
Python openCV codesPython openCV codes
Python openCV codes
Amarjeetsingh Thakur
 
Steemit html blog
Steemit html blogSteemit html blog
Steemit html blog
Amarjeetsingh Thakur
 
Python OpenCV Real Time projects
Python OpenCV Real Time projectsPython OpenCV Real Time projects
Python OpenCV Real Time projects
Amarjeetsingh Thakur
 
Adafruit_IoT_Platform
Adafruit_IoT_PlatformAdafruit_IoT_Platform
Adafruit_IoT_Platform
Amarjeetsingh Thakur
 
Core python programming tutorial
Core python programming tutorialCore python programming tutorial
Core python programming tutorial
Amarjeetsingh Thakur
 
Python openpyxl
Python openpyxlPython openpyxl
Python openpyxl
Amarjeetsingh Thakur
 
Introduction to Internet of Things (IoT)
Introduction to Internet of Things (IoT)Introduction to Internet of Things (IoT)
Introduction to Internet of Things (IoT)
Amarjeetsingh Thakur
 
Introduction to Node MCU
Introduction to Node MCUIntroduction to Node MCU
Introduction to Node MCU
Amarjeetsingh Thakur
 
Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)
Amarjeetsingh Thakur
 
Introduction to MQ Telemetry Transport (MQTT)
Introduction to MQ Telemetry Transport (MQTT)Introduction to MQ Telemetry Transport (MQTT)
Introduction to MQ Telemetry Transport (MQTT)
Amarjeetsingh Thakur
 
Arduino Interfacing with different sensors and motor
Arduino Interfacing with different sensors and motorArduino Interfacing with different sensors and motor
Arduino Interfacing with different sensors and motor
Amarjeetsingh Thakur
 
Image processing in MATLAB
Image processing in MATLABImage processing in MATLAB
Image processing in MATLAB
Amarjeetsingh Thakur
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
Amarjeetsingh Thakur
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
Amarjeetsingh Thakur
 
“Introduction to MATLAB & SIMULINK”
“Introduction to MATLAB  & SIMULINK”“Introduction to MATLAB  & SIMULINK”
“Introduction to MATLAB & SIMULINK”
Amarjeetsingh Thakur
 
Python code for servo control using Raspberry Pi
Python code for servo control using Raspberry PiPython code for servo control using Raspberry Pi
Python code for servo control using Raspberry Pi
Amarjeetsingh Thakur
 
Python code for Push button using Raspberry Pi
Python code for Push button using Raspberry PiPython code for Push button using Raspberry Pi
Python code for Push button using Raspberry Pi
Amarjeetsingh Thakur
 
Python code for Buzzer Control using Raspberry Pi
Python code for Buzzer Control using Raspberry PiPython code for Buzzer Control using Raspberry Pi
Python code for Buzzer Control using Raspberry Pi
Amarjeetsingh Thakur
 
Introduction to Internet of Things (IoT)
Introduction to Internet of Things (IoT)Introduction to Internet of Things (IoT)
Introduction to Internet of Things (IoT)
Amarjeetsingh Thakur
 
Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)Introduction to Things board (An Open Source IoT Cloud Platform)
Introduction to Things board (An Open Source IoT Cloud Platform)
Amarjeetsingh Thakur
 
Introduction to MQ Telemetry Transport (MQTT)
Introduction to MQ Telemetry Transport (MQTT)Introduction to MQ Telemetry Transport (MQTT)
Introduction to MQ Telemetry Transport (MQTT)
Amarjeetsingh Thakur
 
Arduino Interfacing with different sensors and motor
Arduino Interfacing with different sensors and motorArduino Interfacing with different sensors and motor
Arduino Interfacing with different sensors and motor
Amarjeetsingh Thakur
 
Ad

Recently uploaded (20)

Semi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptxSemi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
studyshubham18
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptxWeek 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
The first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptxThe first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptx
Mayank Mathur
 
David Boutry - Mentors Junior Developers
David Boutry - Mentors Junior DevelopersDavid Boutry - Mentors Junior Developers
David Boutry - Mentors Junior Developers
David Boutry
 
Airport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptxAirport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptx
BibekMedhi2
 
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
ijscai
 
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptxFINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
kippcam
 
Structure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS pptStructure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS ppt
Wahajch
 
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
SharinAbGhani1
 
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyRigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Yannis
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagementoperationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
IOt Based Research on Challenges and Future
IOt Based Research on Challenges and FutureIOt Based Research on Challenges and Future
IOt Based Research on Challenges and Future
SACHINSAHU821405
 
May 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information TechnologyMay 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
djiceramil
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
Research_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptxResearch_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptx
niranjancse
 
Introduction to AI agent development with MCP
Introduction to AI agent development with MCPIntroduction to AI agent development with MCP
Introduction to AI agent development with MCP
Dori Waldman
 
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptxSemi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
studyshubham18
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptxWeek 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
The first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptxThe first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptx
Mayank Mathur
 
David Boutry - Mentors Junior Developers
David Boutry - Mentors Junior DevelopersDavid Boutry - Mentors Junior Developers
David Boutry - Mentors Junior Developers
David Boutry
 
Airport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptxAirport_Substation_With_Diagrams (2).pptx
Airport_Substation_With_Diagrams (2).pptx
BibekMedhi2
 
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
Top Cite Articles- International Journal on Soft Computing, Artificial Intell...
ijscai
 
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptxFINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
FINAL 2013 Module 20 Corrosion Control and Sequestering PPT Slides.pptx
kippcam
 
Structure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS pptStructure of OS ppt Structure of OsS ppt
Structure of OS ppt Structure of OsS ppt
Wahajch
 
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
SharinAbGhani1
 
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyRigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Yannis
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagementoperationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
IOt Based Research on Challenges and Future
IOt Based Research on Challenges and FutureIOt Based Research on Challenges and Future
IOt Based Research on Challenges and Future
SACHINSAHU821405
 
May 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information TechnologyMay 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
djiceramil
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
Research_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptxResearch_Sensitization_&_Innovative_Project_Development.pptx
Research_Sensitization_&_Innovative_Project_Development.pptx
niranjancse
 
Introduction to AI agent development with MCP
Introduction to AI agent development with MCPIntroduction to AI agent development with MCP
Introduction to AI agent development with MCP
Dori Waldman
 

Python Numpy Source Codes

  • 1. 1 | P a g e ############################Python Numpy Source Codes###################### Note: Loops are slower than numpy arrays! ############### import numpy as np l=[1,2] nplist = np.array(l) print(nplist) RESULT: [1 2] ################## import numpy as np L=[1,2,3] NA = np.array(L) for i in L: print(i) RESULT: 1 2 3 #################### import numpy as np L=[1,2,3] NA = np.array(L) for i in NA: print(i) RESULT: 1 2 3 ######################## import numpy as np L=[1,2,3] L1=L+[4] #append print(L1) RESULT: [1, 2, 3, 4]
  • 2. 2 | P a g e ######################### import numpy as np import numpy as np L=[1,2,3,4] L.append(5) print(L) RESULT: [1, 2, 3, 4, 5] ######################### import numpy as np L=[1,2,3] NA = np.array(L) print(NA) #NA=[1 2 3] NA1 = NA + [4] #vector addition, 4 is added to each element print(NA1) #NA1=[5 6 7] ########################## import numpy as np L=[1,2,3] NA = np.array(L) print(NA) #NA=[1 2 3] NA.append(8) RESULT: AttributeError: 'numpy.ndarray' object has no attribute 'append' ############################# import numpy as np L=[1,2,3] NA = np.array(L)#[1 2 3] NA2 = NA + NA print(NA2) #Vector addition:[1 2 3]+[1 2 3]=[2 4 6] L2 = L + L print(L2) #List addition is simply concatenation [1, 2, 3, 1, 2, 3] ##########vector addition in list######### L= [1,2,3] L3 = [] for i in L: L3.append(i+i) print(L3) #[2,4,6]
  • 3. 3 | P a g e #########vector multipication###### import numpy as np L=[1,2,3] NA = np.array(L)#[1 2 3] print(2*NA) # vector multiplication [2 4 6] print(2*L) #list multiplication :[1, 2, 3, 1, 2, 3] #############Square operation######## import numpy as np L=[1,2,3] NA = np.array(L)#[1 2 3] print(NA**2) # Square operation: [1 4 9] print(L**2) #TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int' ############List Square operation####### L= [1,2,3] L3 = [] for i in L: L3=i*i print(L3) #[1,4,9] ############Square root operation###### import numpy as np L=[1,2,3] NA = np.array(L)#[1 2 3] print(np.sqrt(NA)) # Square operation: [1. 1.41421356 1.73205081] ############log operation############ import numpy as np L=[1,2,3] NA = np.array(L)#[1 2 3] print(np.log(NA))# log operation:[0. 0.69314718 1.09861229] ###########exponential operation###### import numpy as np L=[1,2,3] NA = np.array(L)#[1 2 3] print(np.exp(NA))# exponential operation:[ 2.71828183 7.3890561 20.08553692] ############################# import numpy as np a=np.array([1,2,3]) b=np.array([[1,2], [3,4], [5,6]]) print(a[0]) #a[0]=1 print(b[0]) #b[0]=[1 2]
  • 4. 4 | P a g e print(b[0][0])# b[0][0]= 1 print(b[0][1])# b[0][1]= 2 M=np.matrix([[1,2], [3,4], [5,6]]) print(M) #Matrix form print(M[0][0]) #M[0][0]=[[1 2]] print(M[0,0]) #M[0,0]=1 ############################ import numpy as np a=np.array([1,2,3]) b=np.array([[1,2], [3,4], [5,6]]) print(b) RESULT: [[1 2] [3 4] [5 6]] #####################Transpose operation############## import numpy as np a=np.array([1,2,3]) b=np.array([[1,2], [3,4], [5,6]]) print(b.T) # Transpose operation RESULT: [[1 3 5] [2 4 6]] #############No. of rows and cols ############## import numpy as np b=np.array([[1,2], [3,4], [5,6]]) print(b.shape) # rows x cols= (3, 2) c=b.T print(c.shape) # rows x cols=(2, 3) ###############To check dimension of array############# import numpy as np a=np.array([1,2,3]) print(a.ndim) #a is 1 dimensional array b=np.array([[1,2], [3,4], [5,6]]) print(b.ndim) #b is 2 dimensional array c=b.T print(c.ndim) #c is 2 dimensional array
  • 5. 5 | P a g e ##############To check total no. of elements in an array########### import numpy as np a=np.array([1,2,3]) print(a.size) #a has 3 elements b=np.array([[1,2], [3,4], [5,6]]) print(b.size) #b has 6 elements c=b.T print(c.size) #c has 6 elements ##############To check data type of an array########### import numpy as np a=np.array([1,2,3]) print(a.dtype) #int32 b=np.array([[1,2], [3,4], [5,6]]) print(b.dtype) #int32 c=b.T print(c.dtype) #int32 ##########data type conversion######## import numpy as np a=np.array([1,2,3]) b=np.array([1,2,3], dtype=np.float32) print(b) #[1. 2. 3.] ##########Check each elemenet size######### import numpy as np a=np.array([1,2,3]) print(a.itemsize) #4 bytes b=np.array([1,2,3], dtype=np.float64) print(b.itemsize) #8 bytes ##########Check minimum and maximum elemenet ####### import numpy as np a=np.array([1,2,3]) print(a.min()) #minimum element is 1 print(a.max()) #maximum element is 3 ##########Check sum of elemenets####### import numpy as np a=np.array([1,2,3]) print(a.sum()) #sum of all elements is 6
  • 6. 6 | P a g e ##########axis sum########## import numpy as np b=np.array([[1,2], [3,4], [5,6]]) print(b.sum(axis=0)) #1+3+5=9, 2+4+6=12, print(b.sum(axis=1)) #1+2=3, 3+4=7, 5+6=11 ########### import numpy as np a=np.zeros((2,3)) #2 rows and 3 cols print(a) RESULT: [[0. 0. 0.] [0. 0. 0.]] ############### import numpy as np b=np.ones((3,2)) print(b) RESULT: [[1. 1.] [1. 1.] [1. 1.]] ########### import numpy as np b=np.ones((3,2), dtype=np.int16) print(b) RESULT: [[1 1] [1 1] [1 1]] ##########Crete random data########### import numpy as np print(np.empty((3,3))) RESULT: [[0.00000000e+000 0.00000000e+000 0.00000000e+000] [0.00000000e+000 0.00000000e+000 1.91697471e-321] [1.93101617e-312 1.93101617e-312 0.00000000e+000]]
  • 7. 7 | P a g e ####################### import numpy as np print(np.empty([3,3])) RESULT: [[6.23042070e-307 3.56043053e-307 1.60219306e-306] [7.56571288e-307 1.89146896e-307 1.37961302e-306] [1.05699242e-307 8.01097889e-307 0.00000000e+000]] ######################## import numpy as np print(np.empty([3,3], dtype=np.int16)) RESULT: After first execution: [[4 0 0] [0 4 0] [0 0 0]] After second execution: [[0 0 0] [0 0 0] [0 0 0]] ################# import numpy as np print(np.arange(0,5)) #[0 1 2 3 4] print(np.arange(0,5, 0.5)) #[0. 0.5 1. 1.5 2. 2.5 3. 3.5 4. 4.5] ################## import numpy as np print(np.linspace(0,5)) #Linearly space the value in range 0 to 5 #By default it takes 50 values RESULT: [0. 0.10204082 0.20408163 0.30612245 0.40816327 0.51020408 0.6122449 0.71428571 0.81632653 0.91836735 1.02040816 1.12244898 1.2244898 1.32653061 1.42857143 1.53061224 1.63265306 1.73469388 1.83673469 1.93877551 2.04081633 2.14285714 2.24489796 2.34693878 2.44897959 2.55102041 2.65306122 2.75510204 2.85714286 2.95918367 3.06122449 3.16326531 3.26530612 3.36734694 3.46938776 3.57142857 3.67346939 3.7755102 3.87755102 3.97959184 4.08163265 4.18367347 4.28571429 4.3877551 4.48979592 4.59183673 4.69387755 4.79591837 4.89795918 5.]
  • 8. 8 | P a g e ############## import numpy as np print(np.linspace(1,5,10)) RESULT: [1. 1.44444444 1.88888889 2.33333333 2.77777778 3.22222222 3.66666667 4.11111111 4.55555556 5. ] ############Create random numbers############# import numpy as np print(np.random.random((2,3))) #dimension is 2 rows X 3 cols RESULT: [[0.13945931 0.16273058 0.56452845] [0.61644482 0.18447141 0.17318377]] ############Reshaping array dimension############# import numpy as np c=np.zeros((2,3)) print(c) print(c.reshape(6,1)) print(c.reshape(3,2)) ############Reshaping array dimension############# import numpy as np c=np.zeros((2,5)) print(c) print(c.reshape(5,-1)) # here 5 rows are created while cols created automatically by using '-1' #############Stack vertically#################### import numpy as np c=np.zeros((2,5)) d=np.ones((1,5)) e=np.vstack((c,d)) print(e) RESULT; [[0. 0. 0. 0. 0.] [0. 0. 0. 0. 0.] [1. 1. 1. 1. 1.]] #############Stack vertically####################
  • 9. 9 | P a g e import numpy as np c=np.zeros((2,5)) d=np.ones((1,5)) e=np.vstack((d,c)) print(e) RESULT: [[1. 1. 1. 1. 1.] [0. 0. 0. 0. 0.] [0. 0. 0. 0. 0.]] #############Stack horizontally#################### import numpy as np c=np.zeros((1,5)) d=np.ones((1,5)) e=np.hstack((d,c)) print(e) RESULT: [[1. 1. 1. 1. 1. 0. 0. 0. 0. 0.]] #########Vertical array Split########### import numpy as np b=np.array([[1,2], [3,4], [5,6]]) print(b) e=np.vsplit(b , 3) #vertical split in 3 parts print(e) RESULT: [[1 2] [3 4] [5 6]] [array([[1, 2]]), array([[3, 4]]), array([[5, 6]])] #########Horizontal array Split########### import numpy as np b=np.array([[1,2], [3,4], [5,6]]) print(b) e=np.hsplit(b , 2) print(e)
  • 10. 10 | P a g e RESULT: [[1 2] [3 4] [5 6]] [array([[1], [3], [5]]), array([[2], [4], [6]])]