0% found this document useful (0 votes)
3 views

numpy - Jupyter Notebook

Uploaded by

xometex256
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)
3 views

numpy - Jupyter Notebook

Uploaded by

xometex256
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/ 4

6/16/24, 5:49 PM numpy - Jupyter Notebook

In [1]: import numpy as np

In [2]: a1 = np.array([10,20,30,40,50])

In [3]: a1

Out[3]: array([10, 20, 30, 40, 50])

In [4]: type(a1)

Out[4]: numpy.ndarray

In [5]: a1.dtype

Out[5]: dtype('int64')

In [6]: a2 = np.array([10,20,30,40,50.0])

In [7]: a2

Out[7]: array([10., 20., 30., 40., 50.])

In [8]: a2.dtype

Out[8]: dtype('float64')

In [9]: a3 = np.array([10,20,30,'a'])

In [10]: a3

Out[10]: array(['10', '20', '30', 'a'], dtype='<U21')

In [11]: a3.dtype

Out[11]: dtype('<U21')

In [12]: a4 = np.array([10,20,30,40,50], dtype=float)

In [13]: a4

Out[13]: array([10., 20., 30., 40., 50.])

In [14]: a4.dtype

Out[14]: dtype('float64')

In [15]: a4.shape

Out[15]: (5,)

localhost:8888/notebooks/Untitled Folder/numpy.ipynb# 1/4


6/16/24, 5:49 PM numpy - Jupyter Notebook

In [20]: a5 = np.array([[1,1,1,1,1],[1,1,1,1,1]])

In [21]: a5

Out[21]: array([[1, 1, 1, 1, 1],


[1, 1, 1, 1, 1]])

In [22]: a5.shape

Out[22]: (2, 5)

In [23]: a6 = np.array([[[1,1,1,1,1],[1,1,1,1,1]],[[1,1,1,1,1],[1,1,1,1,1]]]

In [24]: a6.shape

Out[24]: (2, 2, 5)

In [26]: a7 = np.arange(0,10)

In [27]: a7

Out[27]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

In [28]: a8= np.arange(0,10,2)

In [29]: a8

Out[29]: array([0, 2, 4, 6, 8])

In [30]: a9 = np.arange(1,10,2)

In [31]: a9

Out[31]: array([1, 3, 5, 7, 9])

In [33]: a10 = np.arange(0,9).reshape(3,3)

In [34]: a10

Out[34]: array([[0, 1, 2],


[3, 4, 5],
[6, 7, 8]])

In [35]: a11 = np.random.random((10,5))

localhost:8888/notebooks/Untitled Folder/numpy.ipynb# 2/4


6/16/24, 5:49 PM numpy - Jupyter Notebook

In [36]: a11

Out[36]: array([[0.35105011, 0.20238553, 0.08760314, 0.9607955 , 0.3139777


],
[0.37793176, 0.97763512, 0.79498688, 0.64884081, 0.6314335
4],
[0.51380348, 0.06347662, 0.4900014 , 0.15770357, 0.9429174
],
[0.3217831 , 0.55123828, 0.95921054, 0.86975543, 0.5972358
6],
[0.46111603, 0.32050305, 0.22071535, 0.28385255, 0.0782432
8],
[0.05332095, 0.74271408, 0.77854453, 0.36840096, 0.6544761
6],
[0.62443293, 0.78524565, 0.60530251, 0.21564531, 0.8119490
5],
[0.97735109, 0.05231002, 0.91592143, 0.4171213 , 0.6023990
7],
[0.64175109, 0.50841797, 0.26152518, 0.63766487, 0.7873280
7],
[0.50739811, 0.94751204, 0.7808633 , 0.20898305, 0.7316360
5]])

In [37]: a11.shape

Out[37]: (10, 5)

In [38]: a1

Out[38]: array([10, 20, 30, 40, 50])

In [39]: a1 +10

Out[39]: array([20, 30, 40, 50, 60])

In [40]: a1 - 10

Out[40]: array([ 0, 10, 20, 30, 40])

In [41]: a1 *2

Out[41]: array([ 20, 40, 60, 80, 100])

In [43]: x = np.array([[2,1],[3,4]])
y = np.array([[1,2],[2,1]])

In [45]: x

Out[45]: array([[2, 1],


[3, 4]])

In [46]: y

Out[46]: array([[1, 2],


[2, 1]])

localhost:8888/notebooks/Untitled Folder/numpy.ipynb# 3/4


6/16/24, 5:49 PM numpy - Jupyter Notebook

In [51]: x * y

Out[51]: array([[2, 2],


[6, 4]])

In [52]: x.dot(y)

Out[52]: array([[ 4, 5],


[11, 10]])

In [53]: np.sqrt(x)

Out[53]: array([[1.41421356, 1. ],
[1.73205081, 2. ]])

In [54]: np.log(x)

Out[54]: array([[0.69314718, 0. ],
[1.09861229, 1.38629436]])

In [55]: np.max(a1)

Out[55]: 50

In [56]: np.mean(a1)

Out[56]: 30.0

In [57]: np.min(a1)

Out[57]: 10

In [58]: a1

Out[58]: array([10, 20, 30, 40, 50])

In [59]: a1[1]

Out[59]: 20

In [60]: a1[3:]

Out[60]: array([40, 50])

In [ ]:

localhost:8888/notebooks/Untitled Folder/numpy.ipynb# 4/4

You might also like