2) np.arange(25) is for creating a list from 0 to 24, total is 25 elements.
3) a.reshape((5,5)) means from the list (data source) provided, create a 5*5 array.
Python example:
import numpy as np #1
a = np.arange(25) #2
b = np.arange(25)
print("------- Source -------")
print(a)
print(b)
print("------- Reshape ------")
a = a.reshape((5,5)) #3
b = b.reshape((5,5))
print(a)
print(b)
print("--- After calculation ---")
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a**2)
print(a<b)
print(a>b)
print(a.dot(b))
Result:
------- Source -------
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24]
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24]
------- Reshape ------
[[ 0 1 2 3 4]
[ 5 6 7 8 9]
[10 11 12 13 14]
[15 16 17 18 19]
[20 21 22 23 24]]
[[ 0 1 2 3 4]
[ 5 6 7 8 9]
[10 11 12 13 14]
[15 16 17 18 19]
[20 21 22 23 24]]
--- After calculation ---
[[ 0 2 4 6 8]
[10 12 14 16 18]
[20 22 24 26 28]
[30 32 34 36 38]
[40 42 44 46 48]]
[[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]]
[[ 0 1 4 9 16]
[ 25 36 49 64 81]
[100 121 144 169 196]
[225 256 289 324 361]
[400 441 484 529 576]]
[[ nan 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]]
[[ 0 1 4 9 16]
[ 25 36 49 64 81]
[100 121 144 169 196]
[225 256 289 324 361]
[400 441 484 529 576]]
[[False False False False False]
[False False False False False]
[False False False False False]
[False False False False False]
[False False False False False]]
[[False False False False False]
[False False False False False]
[False False False False False]
[False False False False False]
[False False False False False]]
[[ 150 160 170 180 190]
[ 400 435 470 505 540]
[ 650 710 770 830 890]
[ 900 985 1070 1155 1240]
[1150 1260 1370 1480 1590]]
No comments :
Post a Comment