python - advanced - 16 - Numpy



Numpy 

pip install numpy

Onceki ogrendigimiz listeler array degil, sadece numpy import edildiginde array`e donusturulebiliyorlar.

import numpy as np

py_list = [1,2,3,4,5,6,7,8,9] # type`i => `liste`

np_array = np.array([1,2,3,4,5,6,7,8,9]) # type`i => nd_array

py_multi = [[1,2,3],[4,5,6],[7,8,9]]
np_multi = np_array.reshape(3,3) # matris`e donusturuyor

print(py_multi)
print(np_multi)

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

array olusturma

10 ile 100 arasi 3`er artan array: 
result = np.arange(10,100,3)

print(result)

#
[10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 91 94 97]

sifir`lardan olusmus array

result = np.zeros(10)
print(result)

#
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

veya birlerden olusan
result = np.ones(10)

print(result)

#
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]

belirli araliklarla  artis - 5 parcaya bol:
result = np.linspace(0,100,5)

print(result)

#
[ 0. 25. 50. 75. 100.]

random integer: 
result = np.random.randint(0,10)
print(result) # 6

0-40 arasi rastgele 4 sayi ver:
result = np.random.randint(0,40,4)

print(result)
#
[38 1 18 22]














Comments

Popular posts from this blog

python - pro - 20 - SQLite

python - pro - 21 - NoSQL

python - pro - 19 - MySQL