'Ruby fabula'에 해당되는 글 4건
- 2008/03/25 Nelder Mead method by Python (0) _ beckgom
- 2008/03/15 Python에서 Binary Input/Output (0) _ beckgom
- 2008/03/08 net/http 이미지 url 긁어오기 example (0) _ beckgom
- 2008/03/02 uninitialized constant gem와 같은 에러가 발생할 경우.... (0) _ beckgom
캐삽질해봤음..
덕분에 얻은 것은, python에 조금 익숙해짐과, debugging 방법, 기타 알고리즘..정도...
사용법.
alpha, beta, gamma를 적절한 수로 설정한다. Default로는 1, 2, 0.5로 설정.
Evaluation Function (def Func_eval)를 설정한다. 현재는 two variable function으로 되어 있음.
initial point 3 개를 설정한다.(a1, a2, a3)로 설정이 가능.
signal processing programming에서 가장 많이 사용하는 것이 바로 binary input/output이다.
음성, 오디오, 영상, 이미지 등 signal processing을 하기 위해서는 raw 데이터에서 읽어야 한다.
Python에서 binary file에 대해 input/output 하는 방법은 다음과 같다.
The struct module provides pack() and unpack() functions for working with variable length
binary record formats. The following example shows how to loop through
header information in a ZIP file (with pack codes "H" and
"L" representing two and four byte unsigned numbers respectively):
import struct
data
= open('myfile.zip', 'rb').read()
start = 0
for
i in range(3):
# show the first 3 file headers
start += 14
fields =
struct.unpack('LLLHH', data[start:start+16])
crc32, comp_size, uncomp_size, filenamesize, extra_size
= fields
start += 16
filename = data[start:start+filenamesize]
start +=
filenamesize
extra = data[start:start+extra_size]
print filename, hex(crc32), comp_size, uncomp_size
start
+= extra_size + comp_size # skip to the next
header
(출처 Python-Doc)
struct module에 들어있는 pack 또는 unpack 함수를 사용하여 binary 단위로 processing을 할 수 있다.
같은 ascii로 나오게 되며 이를 이용하여 signal processing에 사용이 가능하다.
Read/write type(int or short or char ...)은 다음과 같이 설정하여 사용할 수 있다.

(출처 Python-Doc)
Graph
그리는데 python이 간단하게 programming이 가능하기 때문에,
앞으로 UI를 만들 때 C에서 processing한 후
file을 전달받아서 화면에 파형을 뿌려주는 예제가 가능
또 다른 예는 FFT는 C로 구현하고 Spectrum은 Python에서 drawing.
이 글은 스프링노트에서 작성되었습니다.
require 'net/http'
h = Net::HTTP.new('www.beckgom.com', 80)
resp, data
= h.get('/index.php', nil)
if resp.message == "OK"
data.scan(/<img src="(.*?)"/) {
|x| puts x }
end
만화나 이딴거 긁어올 때 매우 좋겠는걸?
무흣...-_- 공부할 생각은 안하고..만화나 생각하고 말이지....
이 글은 스프링노트에서 작성되었습니다.
리눅스 Ubuntu(우분투)에서 Ruby(루비)를 설치하다보면 다음과 같은 error가 발생할 때가 있다.
uninitialized constant gem....
uninitialized constant gem와 같은 에러가 발생할 경우....
/usr/bin/gem을 열어서
require 'rubygems'아래
require 'rubygems/gem_runner'를 추가하면 문제 해결...
역시..쉽지않아...
이 글은 스프링노트에서 작성되었습니다.
nelder_mead.py


의견을 달아 주세요