เตรียมพร้อมการใช้งาน ipython shell

array object ในภาษา python ก็มีประโยชน์มากมากแต่ว่าหากเปรียบเทียบกับ matlab หรือ octave ก็ทำให้เห็นว่า array python ก็ขาดไปบางอย่าง อาจจะมองว่า numpy ก็เป็น Advance Array ใน python ด้วยการ Import numpy มาใช้งาน เนื่องจาก Numpy ไม่ได้ติดมากับ library python

import numpy as np
np.__version__
a = np.array([2,3,4])  #ถูก
a = np.array(2,3,4) #ผิด

เริ่มต้นการใช้งาน.

C:\Users\lookmee>ipython --pylab
Python 3.6.0 |Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import numpy as np
In [2]: plot(arange(5))

ความเร็ว ในการคำนวนเปรียบเทียบกับ python list ปรกติ

# เปรียบเทียบตัวอย่างดังนี้ ทำใน ipython

L = range(1000)
%timeit [i**2 for i in L]


a = np.arange(1000)
%timeit a**2

ดึง loop ที่เร็วที่สุดมา 3 loop และนำมาหาค่าเฉลีย

หมายเหตุ หากต้องการทำสอบใน python ปรกติ

python -m timeit -s "lst=range(1000000)"  "[i*2 for i in lst]"

python -m timeit -s "import numpy as np; arr = np.arange(1000000)" "arr*2"
python -m timeit -s "import math; lst = range(1000000)" "[math.sin(i)**2 for i in lst]"

python -m timeit -s "import numpy  as np; arr=np.arange(1000000)" "np.sin(arr)**2"

ระบบการสนับสนุนเอกสาร Document

np.array?

np.lookfor('create array')

np.con*?

help(numpy)

Linear Alegebra ในรูปแบบของ matrices

นำเอา สมการเชิงเส้น (Linear equation) ในตัวแปร x1,x2,...,xn

พัฒนาด้วยภาษา C

เทียบเท่า Matlab

results matching ""

    No results matching ""