Wednesday, April 29, 2009

Use append to construct 2-dimension array

How to use array.append to construct or build 2-dimension array?

Here we go! Do it lie following step!
===============================
#create two-dimensional array
arr = []
for line in startfile.readlines():
    littlearr = []
    for letter in line.strip():
        littlearr.append(letter)
    arr.append(littlearr)
===============================

Matplotlib - how to define a size of figure

Users can manually setup the figure size by the 4 attributes when using matplotlib,
Left, Bottom, Width, Height.
This is a example to help users understand how to setup the variables.

Width and Height are easier to image.
They means the width and height of a figure.
Left means the figure(the figure is not including the axes and label) start from left.
Left is 0. You will see the figure is sticked on the left boundary.
Bottom means the figure start from the bottom.
Bottom is 0. You will see the figure is sticked on the bottom line.

Let's see the example figures.

Let's see the different one. You should understand how to control it.
All values of 4 variable is 0~1. Good luck and have fun!


Wednesday, April 8, 2009

Tuesday, April 7, 2009

Boot loader on Ubuntu

How to change the boot sequence if you have multi-OS on your PC?

  1. Open Synaptic Package Manager
  2. Search kgrubeditor, kg is enough. You will see kgrubeditor in your search result.
  3. Install it, then you can modify the default OS.

Or
  1. Open your terminal
  2. Type $ sudo apt-get install kgrubeditor
Or
  1. Open your terminal
  2. Type $ sudo gedit /boot/grub/menu.list
http://www.kde-apps.org/content/show.php?content=75442

Friday, April 3, 2009

LMA on Python

Python, actually Scipy, provides the Levenberg-Marquardt algortihm for solving least-square problem. It's called leastq in scipy.optimize package. There are a lot's optimization algorithms.
http://docs.scipy.org/doc/scipy/reference/optimize.html

Basically, It was coded by fortran. http://www.netlib.org/minpack/
You can download the test code for fortran version form http://www1.fpl.fs.fed.us/minpack.ls.test.html

You can use it directly by calling "scipy.optimize.leastsq" after including "from scipy.optimize import leastsq"

These are good simple examples.


Reminder:
Be careful the arrary usage of input data x and y.

Memo to use Python: optparse

Reference:

This is an simple example of optparse, a command line parser in Python.
You can copy it and modify it free.

# Loading command line parser, this is better.
import optparse
# Loading basic libraries
import sys

# This is command line parser setting
usage = "Usage: #pprog [options] arg"
parser = optparse.OptionParser(usage)
# You can add the options in the following format
parser.add_option('-o', '--output', 
                  dest="output_filename", 
                  default="default.out",
  help="Given a output",
                  )
parser.add_option('-i', '--input',
                  dest="input_filename",
                  default="default.in",
  help="Given a input",
                  )
parser.add_option('-v', '--version',
                  dest="version",
                  default=1.0,
                  type="float",
  help="Show the version",
                  )
parser.add_option('-d', '--debug',
                  dest="debug",
                  default=False,
                  action="store_true",
  help="Debug mode, all information will be printed in debug.out",
                  )  
parser.add_option('-g', '--graphic',
                  dest="graphic",
                  default=False,
                  action="store_true",
  help="Graphic mode, print the result in graphic",
                  )   
options, remainder = parser.parse_args()

# This is main function
# if no option print help()
if len(sys.argv) == 1:
parser.print_help()
# if we have more than one option, print option table
if len(sys.argv) > 1:
print 'ARGV      :', sys.argv[1:]
print 'VERSION   :', options.version
print 'INPUT     :', options.input_filename
print 'OUTPUT    :', options.output_filename
print 'DEBUG     :', options.debug
print 'GRAPHIC   :', options.graphic
# Then you can use the options to setting your variables and parameters

Reminder #1
if you use the function, "defualt", on your options.debug, you won't get the options.debug == None, because options.debug will have a defualt.
So you are impossible to use if statements to get options.debug == None.
If you need the if statements to check options.debug == None, you have to remove the function, options.default.

遺失HAL.dll檔

如果電腦開機後,出現此訊息,
Windows 無法啟動,因為下列檔案遺失或損毀:
Windows\System32\Hal.dll

修復方法有
1. 就想辦法複製一份Hal.dll進去,有曾經修復過,不過我覺得不是正確作法,而且有時候此檔案還在,你可以嘗試複製新的進去,舊的先保留起來。如果還是不能啟動WINXP,就嘗試2。
2. 原版光碟開機,啟動修復管理員,輸入 copy hal.dll C:\Windows\system32\hal.dll。也是要注意如果舊的hal.dll還在,最好先改名稱,備份起來。
3. 若發生原因是如果 Boot.ini 檔遺失、損壞或包含不正確的項目,則可能發生此問題。就用拿原版XP光碟啟動,修復Boot.ini囉!

如果要解決此問題,請從 Windows XP CD 啟動電腦,並啟動「修復主控台」,然後使用 Bootcfg.exe 工具重建 Boot.ini 檔案。如果要執行這項操作,請依照下列步驟執行:

  1. 將電腦設定為從 CD-ROM 光碟機或 DVD-ROM 光碟機啟動。如需有關如何執行這項操作的資訊,請參閱電腦的說明文件,或與您的電腦製造商連絡。
  2. 將 Windows XP 光碟插入 CD-ROM 光碟機或 DVD-ROM 光碟機中,然後重新啟動電腦。
  3. 當您看到 Press any key to boot from CD (請按任意鍵從光碟開機) 訊息時,請按任意鍵,以從 Windows XP 光碟啟動電腦。
  4. 當您看見 Welcome to Setup (歡迎使用安裝程式) 訊息時,請按 R 以啟動「修復主控台」。
  5. 如果您使用雙開機方式或多開機方式的電腦,請從「修復主控台」選取您所必須使用的安裝。
  6. 當系統提示您時,請輸入系統管理員密碼,然後按 ENTER。
  7. 在命令提示處輸入 bootcfg /list(中間有一個空格),再按 ENTER。畫面上會顯示目前 Boot.ini 檔中的項目。 如果顯示沒有檔案,就表示windows真的找不到Boot.ini或是Boot.ini損壞。
  8. 在命令提示處輸入 bootcfg /rebuildt(中間有一個空格),再按 ENTER。此命令會在電腦的硬碟上進行 Windows XP、Microsoft Windows 2000 或 Microsoft Windows NT 安裝的掃描,然後顯示掃描的結果。請依照畫面上的指示將 Windows 安裝程式新增到 Boot.ini 檔案中。

例如,依照這些步驟將 Windows XP 安裝程式新增到 Boot.ini 檔案中:

a. 當您收到類似下列的訊息時,按下 Y:
Total identified Windows installs: (識別的 Windows 安裝總數:)1

[1] C:\Windows
Add installation to boot list? (新增安裝程式到開機清單?)(Yes/No/All) (是/否/全部)


b. 您會收到類似下列的訊息:
Enter Load Identifier (輸入載入識別碼)
此為作業系統的名稱。當您收到這項訊息時,請輸入作業系統的名稱,然後按 ENTER。

  • 此為 Microsoft Windows XP Professional (商用版)
  • 或 Microsoft Windows XP Home Edition (家用版)。

c. 您會收到類似下列的訊息:
Enter OS Load options (輸入 OS 載入選項)
當您收到這項訊息時,請輸入 /fastdetect,然後按 ENTER。


參考
http://60.248.128.85/bbs/dispbbs.asp?boardID=67&ID=18584&page=1
http://blog.yam.com/ajuang/article/1272723
http://tw.myblog.yahoo.com/minicaesar/article?mid=119
http://tw.myblog.yahoo.com/ceyi-udwebs/article?mid=55&prev=-1&next=54
因為我的電腦原本有Ubuntu,所以開機後變成有兩個XP,一個 Ubuntu,反正不管了,以後有時間再處理。

Boot.ini錯誤的原因,應該是因為我用ubuntu玩Gparted的後遺症,不能說Gparted不好,因為我的C槽剩太少空間,重整也沒辦法把檔案整理乾淨,所以可能會使Gparted運作不良吧?或許,我亂猜的。
這次,是用bootcfg /rebuild救回來的。


Windows XP修復主控台的指令請參考如下:
Attrib 變更檔案或目錄的屬性。
Batch 執行文字檔中指定的指令。
Bootcfg開機檔案 (boot.ini) 設定及修復。
Chdir (Cd) 顯示目前目錄的名稱,或變更目前的目錄。
Chkdsk 檢查磁碟並顯示狀態報告。
Cls 清除螢幕。
Copy 將單一檔案複製到其他位置。
Delete (Del) 刪除一個或多個檔案。
Dir 顯示目 ..

參考
http://bbs-mychat.com/reads.php?fsz=b&fid=351&tid=202736&page=e

Wednesday, April 1, 2009

Windows的C槽容量不夠怎麼辦?

The C partition is not enough! How to increase the volume of C???
這個標題應該會是很多人會遇到的問題,不過我想高手都知道怎麼解,純粹寫給自己方便用。

有個軟體是大家比較熟知的,PartitionMagic,不過這要錢,網路上破解的又大多有木馬。

所以我是使用Gparted,Gnome上的免費工具,前提是你要有空間裝Ubuntu,然後使用Gparted來重新調整C槽的大小,例如把D槽縮小,多出來的空間給C槽。
You can use a software, Gparted, free tool of Gnome. First of all, you have to install Ubuntu, you can try Wubi, a windows installer of Ubuntu. It is easy as other installers on windows. 

官方教學已經很清楚了,http://wiki.ubuntu-tw.org/index.php?title=GParted
BTW, I can't find a good instruction in English. Please ask it to Uncle Google. :P

Step1. 安裝Ubuntu,也可以考慮安裝Wubi,http://wubi-installer.org/,就像安裝Windows軟體一樣方便。
  • Install Ubuntu or Wubi

Step2. 重新開機,選擇Ubuntu啟動,進入後,安裝Gparted和ntfsprogs,指令是
  • Reboot, choose Ubuntu and install Gparted and ntfsprogs
  • $ sudo apt-get update
  • $ sudo apt-get install gparted ntfsprogs
Step3.  啟動Gparted後,按照官方教學操作即可。
  • Execute Gparted. Before repartition, please backup your important files and scan and defrage your partition first.

Clicky

Clicky Web Analytics