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

B1Numpy - Ipynb - Colab

The document is a Jupyter notebook containing Python code using the NumPy library to create and manipulate 2D arrays. It demonstrates various operations such as creating arrays, accessing elements, performing arithmetic operations, and combining arrays. Key outputs include array dimensions, item sizes, and basic statistics like minimum, maximum, and sum.

Uploaded by

newberk0910
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)
18 views2 pages

B1Numpy - Ipynb - Colab

The document is a Jupyter notebook containing Python code using the NumPy library to create and manipulate 2D arrays. It demonstrates various operations such as creating arrays, accessing elements, performing arithmetic operations, and combining arrays. Key outputs include array dimensions, item sizes, and basic statistics like minimum, maximum, and sum.

Uploaded by

newberk0910
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

09:34 18/4/25 B1Numpy.

ipynb - Colab

B1 tạo mảng 2 chiều từ 1 - 9

import numpy as np
a=np.array([(1,2,3),(4,5,6),(7,8,9)])
print(a)

[[1 2 3]
[4 5 6]
[7 8 9]]

B2 tạo một numpy array

import numpy as np
import sys
list1 = range(1000)
print(sys.getsizeof(list1) * len(list1))
num1 = np.arange(1000)
print(num1.size * num1.itemsize)

48000
8000

#B2
import numpy as np
a = np.array([(1,2,3),(4,5,6),(7,8,9)])
print(a.ndim)
print(a.itemsize)
print(a.dtype)
print(a.size)
print(a.shape)

2
8
int64
9
(3, 3)

#B3
import numpy as np
a = np.array([(1,2,3),(4,5,6),(7,8,9)])
print(a.ravel())

[1 2 3 4 5 6 7 8 9]

#B4
import numpy as np
a = np.array([(1,2,3),(4,5,6),(7,8,9)])
print(a[2,1])

#B5
import numpy as np
a = np.array([(1,2,3),(4,5,6),(7,8,9)])
print(a[2,0])

#B6
import numpy as np
a = np.array([(1,2,3),(4,5,6),(7,8,9)])
print(a.min())
print(a.max())
print(a.sum())

1
9
45

https://colab.research.google.com/drive/1vPAOEb8-6k4qCAXMW0eh_cawnhKZvReP#scrollTo=_-lnNnfHvGqm&uniqifier=1&printMode=true 1/2
09:34 18/4/25 B1Numpy.ipynb - Colab
#B7
import numpy as np
x= np.array([(1,2,3),(3,4,5)])
y= np.array([(1,2,3),(3,4,5)])
print(x+y)
print(x-y)
print(x*y)
print(x/y)

[[ 2 4 6]
[ 6 8 10]]
[[0 0 0]
[0 0 0]]
[[ 1 4 9]
[ 9 16 25]]
[[1. 1. 1.]
[1. 1. 1.]]

#B8
import numpy as np
x= np.array([(1,2,3),(3,4,5)])
y= np.array([(1,2,3),(3,4,5)])
print(np.vstack((x,y)))
print(np.hstack((x,y)))

[[1 2 3]
[3 4 5]
[1 2 3]
[3 4 5]]
[[1 2 3 1 2 3]
[3 4 5 3 4 5]]

https://colab.research.google.com/drive/1vPAOEb8-6k4qCAXMW0eh_cawnhKZvReP#scrollTo=_-lnNnfHvGqm&uniqifier=1&printMode=true 2/2

You might also like