8/10/23, 5:55 PM numpy.
ipynb - Colaboratory
import numpy as np
a = np.arange(15).reshape(3, 5)
a
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
a.shape
(3, 5)
import numpy as np
a = np.array([2,3,4])
a
array([2, 3, 4])
a.dtype
dtype('int64')
b=np.array([1.2,1.5,2.3])
b.dtype
dtype('float64')
b=np.array([(2.2,2,3), (1,2,3)])
b
array([[2.2, 2. , 3. ],
[1. , 2. , 3. ]])
c = np.array( [ [1,2], [3,4] ], dtype=complex )
c
array([[1.+0.j, 2.+0.j],
[3.+0.j, 4.+0.j]])
np.ones( (2,3,4), dtype=np.int16 )
array([[[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]],
[[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]]], dtype=int16)
https://colab.research.google.com/drive/1oIAH5AedNJBC289InmNuW471i82f_DwN#scrollTo=q1xL9TheY8jL&printMode=true 1/4
8/10/23, 5:55 PM numpy.ipynb - Colaboratory
np.arange( 10, 50, 7 )
array([10, 17, 24, 31, 38, 45])
np.arange(1,5,0.4)
array([1. , 1.4, 1.8, 2.2, 2.6, 3. , 3.4, 3.8, 4.2, 4.6])
from numpy import pi
np.linspace( 0, 9, 9 )
array([0. , 1.125, 2.25 , 3.375, 4.5 , 5.625, 6.75 , 7.875, 9. ])
a = np.arange(6)
print(a)
[0 1 2 3 4 5]
b = np.arange(12).reshape(4,3)
print(b)
[[ 0 1 2]
[ 3 4 5]
[ 6 7 8]
[ 9 10 11]]
print(np.arange(10000))
[ 0 1 2 ... 9997 9998 9999]
c = np.arange(24).reshape(2,3,4)
print(c)
[[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
[[12 13 14 15]
[16 17 18 19]
[20 21 22 23]]]
a = np.ones((2,3), dtype=int)
b = np.random.random((2,3))
a *= 3
a
array([[3, 3, 3],
[3, 3, 3]])
b+=a
b
https://colab.research.google.com/drive/1oIAH5AedNJBC289InmNuW471i82f_DwN#scrollTo=q1xL9TheY8jL&printMode=true 2/4
8/10/23, 5:55 PM numpy.ipynb - Colaboratory
array([[3.62368162, 3.62003885, 3.08586218],
[3.04014853, 3.29067239, 3.78910069]])
d = np.exp(c*1j)
d
array([[[ 1. +0.j , 0.54030231+0.84147098j,
-0.41614684+0.90929743j, -0.9899925 +0.14112001j],
[-0.65364362-0.7568025j , 0.28366219-0.95892427j,
0.96017029-0.2794155j , 0.75390225+0.6569866j ],
[-0.14550003+0.98935825j, -0.91113026+0.41211849j,
-0.83907153-0.54402111j, 0.0044257 -0.99999021j]],
[[ 0.84385396-0.53657292j, 0.90744678+0.42016704j,
0.13673722+0.99060736j, -0.75968791+0.65028784j],
[-0.95765948-0.28790332j, -0.27516334-0.96139749j,
0.66031671-0.75098725j, 0.98870462+0.14987721j],
[ 0.40808206+0.91294525j, -0.54772926+0.83665564j,
-0.99996083-0.00885131j, -0.53283302-0.8462204j ]]])
b = np.arange(12).reshape(3,4)
b
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
a = np.arange(10)**4
a
array([ 0, 1, 16, 81, 256, 625, 1296, 2401, 4096, 6561])
a[2]
16
a[2:5]
array([ 16, 81, 256])
a[ : :-1]
array([6561, 4096, 2401, 1296, 625, 256, 81, 16, 1, 0])
for i in a:
print(i**(1/3.))
0.0
1.0
2.5198420997897464
4.3267487109222245
6.3496042078727974
https://colab.research.google.com/drive/1oIAH5AedNJBC289InmNuW471i82f_DwN#scrollTo=q1xL9TheY8jL&printMode=true 3/4
8/10/23, 5:55 PM numpy.ipynb - Colaboratory
8.549879733383484
10.902723556992836
13.390518279406722
15.999999999999998
18.720754407467133
error 0s completed at 5:55 PM
https://colab.research.google.com/drive/1oIAH5AedNJBC289InmNuW471i82f_DwN#scrollTo=q1xL9TheY8jL&printMode=true 4/4