Posts

Showing posts from 2009

Cell Array Structure in Numpy

โอ้ว หลังจากpost ใน www.stackoverflow.com สักระยะ ระหว่างการเปลี่ยน code matlab ให้ เป็น python - numpy โดย มีปัญหาคือ cell array ใน matlab จะมาเป็น numpy structure ยังงัย ในที่สุดก็ได้คำตอบจากท่าน thrope ใน stackoverflow ได้แนะนำ linkไป http://docs.scipy.org/doc/scipy/reference/tutorial/io.html#matlab-cell-arrays และก็ได้บอกว่า ให้กำหนด dtype=numpy.object ตัวอย่างเช่น >>import numpy >>a = numpy.zeros((2,2),dtype=numpy.object) เท่านี้ เราจะสามารถเพิ่ม ค่าแบบใดๆ เข้าไปก็ได้เช่น >>a[0,0] = numpy.zeros((3,4)) >>a[0,1] = numpy.zeros((2,2)) ้hahahah มันยอดไปเลยไหมหละคับ

Warm Night with my girlfriend at my Labs

อืม ท่าทางเกือบจะเช้าัวันศุกรแลว้สินะ ขณะที่ผมกำลังเขียนบทความนี้ บนตักของกระผมก็มีผู้หญิงที่แสนน่ารัก(แฟนผมเอง หึหึหึ)เอาหัววางพิงอยู่ ว่าแล้วเธอก็หลับไปแล้วซะด้วย ช่วงเวลานี้ เป็นช่วงเวลาที่ดีอย่างหนักเลยหนะเนี่ย และระหว่างนี้ ผมก็ได้ convert matlab code ไปเป็น python ด้วยความร่วมมือของ numpy กับ stackoverflow และการโหลดไฟลจาก matlab ที่เซฟในรูปแบบของ value1,value2\n value1,value2\n ก็สามารถโหลดเข้ามาใน python โดย f = numpy.loadtxt('c:\\data001.txt',dtype='float',delimiter=',') กลายมาเป็น numpy.ndarray type ได้อย่างง่ายดาย ฮ่าๆๆๆๆ หลังจากก่อนหน้านี้ประมาณ สามชั่วโมงก่อน กระผมได้มีความยุ่งยากกับ การ convert matlab command บางตัวเช่น repmat สุดท้ายก็หาทางเลี่ยงๆไปได้ หึหึหึ

convert matlab's data to python's data

ขณะที่กำลัง debug เราสามารถใช้ command ที่ prompt K>> dlmwrite('yourfile.txt',Variable,'delimiter','\t','precision','%.6f','newline','pc') เป็นการ เขียนไฟล yourfile.txt โดยเอา ค่า ใน ตัวแปร matric Variable ที่มี delimiter คือ tabs ทศนิยม precision เป็น 6 ตำแหน่ง float ขึ้นบรรทัดใหม่สำหรับ pc

คำคม(shape word)

หึหึหึ คำคมต่างที่เกิดขึ้นในโลกนี้มักจะเข้ากันกับสถานการณ บางอย่างที่ผมเจอในชีวิตประจำวัน เมื่อไม่นานมานี้ แฟนผมได้เอ่ย คำคมเด็ดๆ ที่ฟังแล้วเหมือนรู้สึกว่าบรรยากาศจะสไตลญี่ปุ่นหรือ เกาหลีขึ้น มาทันที :) น่าเสียดายที่ขณะที่ผมเขียนblog อยู่นี่ ดันเสือกจำไม่ได้ซะนี่ ถ้าเสือกจำได้ขึ้นมาจะเอามาบันทึกเอาไว้อีก

Sort Object in List

บันทึกการ sort object ที่สร้างจาก class ที่ต้องการใน list class chromosome: def __init__(self,err): self.err = some error value ........ class content ....... suppose c1,c2,c3,c4 create from class chromosome and hav attr err every instance >>mlist = [c1,c2,c3,c4] if we want sort by attr err .... :) we need import operator and do mlist.sort(key=operator.attrgetter('err')) haha i think i got what i want!!!!

yoh, Sort dict

have a problem with sorting dict by value!!! found something interesting on http://code.activestate.com/recipes/304440/ by Nick Coghlan let's see >>d = {'a':0,'b':1,'c':2} >>d #will get {'a':0,'c':2,'b':1} some solution from Nick >>from operator import itemgetter >>print sorted(d.items(),key=itemgetter(1)) #we get [('a':0),('b':1),('c':2)] # >>>>> a list of tuples it might be useful in the future!!!:) thank nick and activestate

Using Pydev and Eclipse for Prototyping

Image
I'm doing a proof of concept model by using Viterbi Algorithm (cause confusing of matlabs' view and hungry to use python), By Eclipse IDE and PyDev ... Things will be like this below!!!!! *ps capture image from gimp Hope this work will be done ,soon!!!! :> and detail will come out later---:

Hello World

Hello My New Blog, We'll hav fun together :o