You are on page 1of 26

Bilimsel Hesaplamalar

Bilimsel Hesaplama Nedir ?


Bilgisayar programları kullanılarak sayısal teknikler ile mühendislik
ve bilimsel problemlerin analizi ve çözümlemesi
Diller ve Araçlar

MATLAB, GNU Octavia, Scilab, Mathcad, Mathematica, Maple,


SAGE gibi araçlar mevcut
Python-Neler Yapılabilir


Web Geliştime (Django, Pyramid, Flask)

Veri Analizi (Seaborn, Mapplotlib)

Oyun Geliştirme (Pygame)

Robotik Uygulamalar
Araçlar


IDLE, Spyder (Geliştirme Ortamları)

Numpy, Matplotlib, Pandas… yüzlerce (Kütüphaneler)
Numpy


Python Kütüphanesidir

Arraylarla çalışır

(Num)erical (Py)thon → NumPy
Neden Var?


Pythonda diziler var, ama yavaş çalışıyor

Yaklaşık 50 kat daha hızlı

Yardımcı birçok metot var

Veri biliminde genellikle dizilerle çalışılır
Numpy- arrays

List ile çok benzer fakat;



Elemanları aynı tip olabilir. (int, float ve complex)

Eleman sayısı belli olmalıdır.

“numpy” ile ulaşılabilir.
arrays

import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr)
print(type(arr))

zeros = np.zeros(5)

zeros=np.zeros(5,4)

ones = np.ones(5)

ones = np.ones((5, 4))

random = np.random.rand(2, 3)

random = np.random.randint(50, 100, 5)
Numpy Metotları

index:
arr = np.array([[1,2,3,4,5], [6,7,8,9,10]])
print('2nd element on 1st row: ', arr[0, 1])
slice:
arr = np.array([1, 2, 3, 4, 5, 6, 7])
print(arr[1:5])
print(arr[-3:-1])
type:
arr = np.array([1, 2, 3, 4], dtype='S') or ‘i4’
Numpy Index

import numpy as np
arr = np.array([1, 2, 3])
for x in arr:
print(x)
arr2 = np.array([[1, 2, 3], [4, 5, 6]])
for x in arr2:
for y in x:
print(y)
Numpy nditer

Tüm elemanları tek forla dolaşmak için;

import numpy as np
arr = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
for x in np.nditer(arr):
print(x)
Numpy where

Tüm
import numpy as np
arr = np.array([1, 2, 3, 4, 5, 4, 4])

x = np.where(arr == 4)

print(x)
Numpy where-2

Tüm elemanları tek forla dolaşmak için;

import numpy as np
arr = np.array([1, 2, 3, 4, 5, 6, 7, 8])
x = np.where(arr%2 == 0)
print(x)
Numpy Sort

import numpy as np
arr = np.array(['banana', 'cherry', 'apple'])
print(np.sort(arr))
Mapplotlib


İki boyutlu çizim kütüphanesi
Matplotlib -Örnek

import matplotlib.pyplot as plt


import numpy as np

xpoints = np.array([0, 6])


ypoints = np.array([0, 250])

plt.plot(xpoints, ypoints)
plt.show()
numpy-matplot

import numpy as np
import matplotlib.pyplot as plt

f = lambda x: np.exp(-x**2)*np.sin(x)
x = np.linspace(-3, 3, 101)
plt.plot(x, f(x))
plt.show()
Örnek-2

import matplotlib.pyplot as plt


import numpy as np

ypoints = np.array([3, 8, 1, 10, 5, 7])

plt.plot(ypoints)
plt.show()
Örnek-Histogram

import numpy as np
x = np.random.normal(170, 10, 250)
print(x)
Pie Chart

import matplotlib.pyplot as plt


import numpy as np

y = np.array([35, 25, 25, 15])

plt.pie(y)
plt.show()
Python

Statik analiz: Yapısal elemanların yer değiştirmelerini, gerilmelerini ve kuvvet


dağılımlarını hesaplama.
Yük analizi: Farklı yük türlerine (merkezi yükler, dağıtılmış yükler, rüzgar yükleri vb.)
dayalı olarak yapı elemanları üzerindeki etkilerin hesaplanması.
Kesit analizi: Betonarme, çelik veya ahşap yapı elemanlarının kesit boyutlarının
hesaplanması.
Hesaplamalı betonarme tasarımı: Betonarme elemanların boyutlarının ve donatı miktarının
hesaplanması.
Hesaplamalı çelik tasarımı: Çelik yapı elemanlarının boyutlarının ve bağlantılarının
hesaplanması.
Plaka analizi: Plakaların yer değiştirmelerini, gerilmelerini ve taşıma kapasitelerini hesaplama.
Kiriş analizi: Kirişlerin yer değiştirmelerini, gerilmelerini ve taşıma kapasitelerini hesaplama.
Python-Insaat Mühendisliği
Temel analizi: Farklı tipteki temellerin (şerit temel, plak temel, kazık temel vb.) taşıma kapasitelerinin
hesaplanması.
Zemin analizi: Zemin parametrelerinin hesaplanması, zemin davranışının modellenmesi ve temel-zemin
etkileşimi analizi.
Rüzgar etkilerinin hesaplanması: Yapıya etki eden rüzgar yüklerinin hesaplanması ve yapısal tepkilerin analizi.
Deprem etkilerinin hesaplanması: Deprem yüklerinin hesaplanması, yapıların dinamik analizi ve yapısal
tepkilerin değerlendirilmesi.
Hidrolik hesaplamalar: Akışkan mekaniği prensiplerine dayalı olarak suyun akış hızı, basınç kaybı, kanal akışı
vb. hesaplamalar.
Malzeme seçimi: Belirli bir yapısal elemanın boyutları ve yükler göz önünde bulundurularak en uygun malzeme
seçiminin hesaplanması.
Yer değiştirme ve deformasyon analizi: Yapı elemanlarının yer değiştirmeleri ve deformasyonları üzerine
analizlerin yapılması.
Yapısal optimizasyon: Verilen bir kısıtlama altında en iyi yapısal çözümün bulunması.
CheatSheet
Python For Data Science Cheat Sheet Inspecting Your Array Subsetting, Slicing, Indexing Also see Lists
>>> a.shape Array dimensions Subsetting
NumPy Basics >>>
>>>
len(a)
b.ndim
Length of array
Number of array dimensions
>>> a[2]
3
1 2 3 Select the element at the 2nd index
Learn Python for Data Science Interactively at www.DataCamp.com >>> e.size Number of array elements >>> b[1,2] 1.5 2 3 Select the element at row 1 column 2
>>> b.dtype Data type of array elements 6.0 4 5 6 (equivalent to b[1][2])
>>> b.dtype.name Name of data type
>>> b.astype(int) Convert an array to a different type Slicing
NumPy >>> a[0:2]
array([1, 2])
1 2 3 Select items at index 0 and 1
2
The NumPy library is the core library for scientific computing in Asking For Help >>> b[0:2,1] 1.5 2 3 Select items at rows 0 and 1 in column 1
>>> np.info(np.ndarray.dtype) array([ 2., 5.]) 4 5 6
Python. It provides a high-performance multidimensional array
Array Mathematics
1.5 2 3
>>> b[:1] Select all items at row 0
object, and tools for working with these arrays. array([[1.5, 2., 3.]]) 4 5 6 (equivalent to b[0:1, :])
Arithmetic Operations >>> c[1,...] Same as [1,:,:]
Use the following import convention: array([[[ 3., 2., 1.],
>>> import numpy as np [ 4., 5., 6.]]])
>>> g = a - b Subtraction
array([[-0.5, 0. , 0. ], >>> a[ : :-1] Reversed array a
NumPy Arrays [-3. , -3. , -3. ]])
array([3, 2, 1])

>>> np.subtract(a,b) Boolean Indexing


1D array 2D array 3D array Subtraction
>>> a[a<2] Select elements from a less than 2
>>> b + a Addition 1 2 3
array([[ 2.5, 4. , 6. ], array([1])
axis 1 axis 2
1 2 3 axis 1 [ 5. , 7. , 9. ]]) Fancy Indexing
1.5 2 3 >>> np.add(b,a) Addition >>> b[[1, 0, 1, 0],[0, 1, 2, 0]] Select elements (1,0),(0,1),(1,2) and (0,0)
axis 0 axis 0 array([ 4. , 2. , 6. , 1.5])
4 5 6 >>> a / b Division
array([[ 0.66666667, 1. , 1. ], >>> b[[1, 0, 1, 0]][:,[0,1,2,0]] Select a subset of the matrix’s rows
[ 0.25 , 0.4 , 0.5 ]]) array([[ 4. ,5. , 6. , 4. ], and columns
>>> np.divide(a,b) Division [ 1.5, 2. , 3. , 1.5],
Creating Arrays >>> a * b
array([[ 1.5, 4. , 9. ],
Multiplication
[ 4. , 5.
[ 1.5, 2.
,
,
6.
3.
,
,
4. ],
1.5]])

>>> a = np.array([1,2,3]) [ 4. , 10. , 18. ]])


>>> b = np.array([(1.5,2,3), (4,5,6)], dtype = float) >>> np.multiply(a,b) Multiplication Array Manipulation
>>> c = np.array([[(1.5,2,3), (4,5,6)], [(3,2,1), (4,5,6)]], >>> np.exp(b) Exponentiation
dtype = float) >>> np.sqrt(b) Square root Transposing Array
>>> np.sin(a) Print sines of an array >>> i = np.transpose(b) Permute array dimensions
Initial Placeholders >>> np.cos(b) Element-wise cosine >>> i.T Permute array dimensions
>>> np.log(a) Element-wise natural logarithm
>>> np.zeros((3,4)) Create an array of zeros >>> e.dot(f) Dot product
Changing Array Shape
>>> np.ones((2,3,4),dtype=np.int16) Create an array of ones array([[ 7., 7.], >>> b.ravel() Flatten the array
>>> d = np.arange(10,25,5) Create an array of evenly [ 7., 7.]]) >>> g.reshape(3,-2) Reshape, but don’t change data
spaced values (step value)
>>> np.linspace(0,2,9) Create an array of evenly Comparison Adding/Removing Elements
spaced values (number of samples) >>> h.resize((2,6)) Return a new array with shape (2,6)
>>> e = np.full((2,2),7) Create a constant array >>> a == b Element-wise comparison >>> np.append(h,g) Append items to an array
>>> f = np.eye(2) Create a 2X2 identity matrix array([[False, True, True], >>> np.insert(a, 1, 5) Insert items in an array
>>> np.random.random((2,2)) Create an array with random values [False, False, False]], dtype=bool) >>> np.delete(a,[1]) Delete items from an array
>>> np.empty((3,2)) Create an empty array >>> a < 2 Element-wise comparison
array([True, False, False], dtype=bool) Combining Arrays
>>> np.array_equal(a, b) Array-wise comparison >>> np.concatenate((a,d),axis=0) Concatenate arrays
I/O array([ 1, 2,
>>> np.vstack((a,b))
3, 10, 15, 20])
Stack arrays vertically (row-wise)
Aggregate Functions array([[ 1. , 2. , 3. ],
Saving & Loading On Disk [ 1.5, 2. , 3. ],
>>> a.sum() Array-wise sum [ 4. , 5. , 6. ]])
>>> np.save('my_array', a) >>> a.min() Array-wise minimum value >>> np.r_[e,f] Stack arrays vertically (row-wise)
>>> np.savez('array.npz', a, b) >>> b.max(axis=0) Maximum value of an array row >>> np.hstack((e,f)) Stack arrays horizontally (column-wise)
>>> np.load('my_array.npy') >>> b.cumsum(axis=1) Cumulative sum of the elements array([[ 7., 7., 1., 0.],
>>> a.mean() Mean [ 7., 7., 0., 1.]])
Saving & Loading Text Files >>> b.median() Median >>> np.column_stack((a,d)) Create stacked column-wise arrays
>>> np.loadtxt("myfile.txt") >>> a.corrcoef() Correlation coefficient array([[ 1, 10],
>>> np.std(b) Standard deviation [ 2, 15],
>>> np.genfromtxt("my_file.csv", delimiter=',') [ 3, 20]])
>>> np.savetxt("myarray.txt", a, delimiter=" ") >>> np.c_[a,d] Create stacked column-wise arrays
Copying Arrays Splitting Arrays
Data Types >>> h = a.view() Create a view of the array with the same data >>> np.hsplit(a,3) Split the array horizontally at the 3rd
>>> np.copy(a) Create a copy of the array [array([1]),array([2]),array([3])] index
>>> np.int64 Signed 64-bit integer types >>> np.vsplit(c,2) Split the array vertically at the 2nd index
>>> np.float32 Standard double-precision floating point >>> h = a.copy() Create a deep copy of the array [array([[[ 1.5, 2. , 1. ],
>>> np.complex Complex numbers represented by 128 floats [ 4. , 5. , 6. ]]]),
array([[[ 3., 2., 3.],
>>>
>>>
np.bool
np.object
Boolean type storing TRUE and FALSE values
Python object type Sorting Arrays [ 4., 5., 6.]]])]

>>> np.string_ Fixed-length string type >>> a.sort() Sort an array


>>> np.unicode_ Fixed-length unicode type >>> c.sort(axis=0) Sort the elements of an array's axis DataCamp
Learn Python for Data Science Interactively

You might also like