c*********n 发帖数: 128 | 1 这程序恰好我以前写过,哈哈。interface稍微不一样,懒得改了,直接贴过来。
import sys
from itertools import permutations
#from operator import __add__
EPS = 0.0000001
isEqual = lambda x, y: [False, True][abs(x-y)
def main():
line = sys.stdin.readline()
numbers = map(float, line.split())
if(len(numbers) == 0): numbers = [2.0, 2.0, 3.0, 5.0]
xs = map(X, numbers, map(str, map(int, numbers)))
expressions = []
findExpression(expressions, 24.0, xs)
print '\n'.join(set(expressions))
class myoperator... 阅读全帖 |
|
m********5 发帖数: 17667 | 2 welcome to python world! I provided a fix which can run flawless to your
class design. Seems like u r from java ;) We should always Keep
in mind that, unlike java, python is a dynamic language.
The counterpart of static class variable of java is class variable.
Using the class name as a reference to a class is very common outside the
class def. However, it is not a very good idea to do so within the class def
, because any class itself is an instance of `type`. The name space looking-
up can m... 阅读全帖 |
|
p**o 发帖数: 3409 | 3
Alternatively, you can build your own parse tree from ground up. E.g. (
assuming fully parenthesized),
class BinTree (object):
def __init__ (self, root=None, left=None, right=None):
self.root = root
self.left = left
self.right = right
def insert_left (self, obj=None):
self.left = BinTree(obj, left=self.left)
return self.left
def insert_right (self, obj=None):
self.right = BinTree(obj, right=self.right)
return self.right
def tok... 阅读全帖 |
|
c******o 发帖数: 1277 | 4 Warning: boring stuff next.太长了,不知道有人看没有。
monad不是一个数据结构,它是一个“类型“的一个“类型”的一个“类型”。(
higher order type)
举例
type:
String
first order type:
List[X], can be List[String], List[Int], List[Double]
higher order type :
Monad, Can be List[X], Try[X], Option[X]
严格来说,Monad是一个高阶的类型,一个“类型“的一个“类型”的一个“类型”
他的定义就是一个类型F,如果能在之上定义
def unit[A](a: => A): F[A]
def flatMap[A,B](ma: F[A])(f: A => F[B]): F[B]
这个类型就是一个monad.
比如List
def unit[A](a: => A): List[A]
给一个x,我能用unit做一个一个元素的List: (x)
scala> List("a")
res0: List[String]... 阅读全帖 |
|
T*******n 发帖数: 493 | 5 EPS file, about 525 bytes, more spaces could be squeezed out.
Intersections of rings are painted over
instead of drawn with clipping paths.
%!PS-Adobe-3.0
%%BoundingBox: 0 0 160 80
/R { 0.816 0 0.141 } def
/G { 0 0.624 0.239 } def
/K { 0 0 0 } def
/Y { 0.957 0.765 0 } def
/C { 0 0.522 0.780 } def
/X {
9 7 roll exch dup 3 2 roll dup 3 1 roll
6 setlinewidth 18 9 7 roll arc 1 1 1 setrgbcolor stroke
4 setlinewidth 18 5 3 roll arc setrgbcolor stroke
} def
/O { -1 361 -1 361 X } def
/T { 237 268 |
|
w*****y 发帖数: 15 | 6 我有个数据,A,B两列是原始数据,C和D列是我希望生成的数据
A B C D
abc 01 1 1
abc 02 1 1
abc 01 2 2
abc 02 2 2
abc 03 2 2
abc 01 3 0
abc 01 4 0
abc 01 5 1
abc 02 5 1
def 01 1 0
def 01 2 3
def 02 2 3
def 03 2 3
def 04 2 3
def 01 3 1
def 02 3 1
ghi 01 1 4
ghi 02 1 4
ghi 03 1 4
ghi 04 1 4
ghi 05 1 4
ghi 01 2 2
ghi 02 |
|
k**********4 发帖数: 16092 | 7 doesnt work:
!-- Global Variables -->
阅读全帖 |
|
d******e 发帖数: 164 | 8 Q2 Revised:
class Graph:
def __init__(self):
self.out_edges = {}
self.in_degrees = {}
def add_vertex(self, v):
if v not in self.out_edges:
self.out_edges[v] = []
self.in_degrees[v] = 0
def add_edge(self, v_out, v_in):
if v_in not in self.out_edges[v_out]:
self.out_edges[v_out].append(v_in)
self.in_degrees[v_in] += 1
def process_words(cur_word, next_word, graph):
for i in xrange(min(len(cur_word), len(... 阅读全帖 |
|
t****a 发帖数: 1212 | 9 第三题很有趣,偶来给个clojure的解
基本思路是
1. 对T做预处理,构建graph,同时,记录每个字符a-z所出现的位置
2. 由于S长度<100,数量却很大(100M),意味着有很多重复,使用memoize function会
大大减少计算量
下面的程序在1/1000大小的S数据集上运行需要1.7秒。观察了一下时间和数据集大小趋
势,在完整数据集上几分钟内也可以产生结果
(def alphabet (map char (range (int \a) (inc (int \z)))))
(def T (vec (take 10000000 (repeatedly #(rand-nth alphabet)))))
(def S (take 100000 (repeatedly (fn [] (take (inc (int (* (rand) 100))) (
repeatedly #(rand-nth alphabet)))))))
(def T-ix (group-by #(T %) (range (count T))))
(def T-map (let [pairs (dist... 阅读全帖 |
|
t****a 发帖数: 1212 | 10 第三题很有趣,偶来给个clojure的解
基本思路是
1. 对T做预处理,构建graph,同时,记录每个字符a-z所出现的位置
2. 由于S长度<100,数量却很大(100M),意味着有很多重复,使用memoize function会
大大减少计算量
下面的程序在1/1000大小的S数据集上运行需要1.7秒。观察了一下时间和数据集大小趋
势,在完整数据集上几分钟内也可以产生结果
(def alphabet (map char (range (int \a) (inc (int \z)))))
(def T (vec (take 10000000 (repeatedly #(rand-nth alphabet)))))
(def S (take 100000 (repeatedly (fn [] (take (inc (int (* (rand) 100))) (
repeatedly #(rand-nth alphabet)))))))
(def T-ix (group-by #(T %) (range (count T))))
(def T-map (let [pairs (dist... 阅读全帖 |
|
p*****2 发帖数: 21240 | 11 来自主题: JobHunting版 - 关于尾递归
尾递归的实现,不过Scala不支持这种递归的优化。
def H(value:Double, n:Int):Double={
H_helper(Array(value),n)(0)
}
def V(value:Double, n:Int):Double={
V_helper(Array(value),n)(0)
}
def H_helper(arr:Array[Double], n:Int):Array[Double]=n match{
case 0 => caclV(arr)
case _ => {
val ar=new Array[Double](arr.length*2)
for(i<- 0 until arr.length) {
ar(2*i)=arr(i)-1
ar(2*i+1)=arr(i)+1
}
... 阅读全帖 |
|
y******u 发帖数: 804 | 12 最近在上coursera的课。看到一个mapreduce的伪实现,参考一下。
in python
MapReduce.py
import json
class MapReduce:
def __init__(self):
self.intermediate = {}
self.result = []
def emit_intermediate(self, key, value):
self.intermediate.setdefault(key, [])
self.intermediate[key].append(value)
def emit(self, value):
self.result.append(value)
def execute(self, data, mapper, reducer):
for line in data:
record = json.loads(line)
mapper(rec... 阅读全帖 |
|
y******u 发帖数: 804 | 13 如果想连连mapreduce算法,下面python script能模拟
MapReduce.py
import json
class MapReduce:
def __init__(self):
self.intermediate = {}
self.result = []
def emit_intermediate(self, key, value):
self.intermediate.setdefault(key, [])
self.intermediate[key].append(value)
def emit(self, value):
self.result.append(value)
def execute(self, data, mapper, reducer):
for line in data:
record = json.loads(line)
mapper(record)
... 阅读全帖 |
|
A*****o 发帖数: 284 | 14 献丑用python实现了一个
class User:
def __init__(self, uid):
self.uid = uid
class Product:
def __init__(self, pid):
self.pid = pid
# given API
# def getProducts(user)
# def getFriends(user)
def cmpFriendBought(a, b): # descending order
return -cmp(a[1][1], b[1][1])
def getRecommendation(user):
counter = {} # product_id => [product, bought_count_by_friends]
myList = getProducts(user)
myBought = set([])
for p in myList:
myBought.add(p.pid)
f... 阅读全帖 |
|
k******r 发帖数: 2243 | 15 好久没有更新了,大家给俺发包子呀,要不俺怎么会有积极性呢。主要的还是最近杂事
比较多。
今天的主题还是Heavy Metal/Hard Rock。其实上次说的激流金属已经是Heavy Metal的
高级阶段了,俺只是想到哪就说到哪。其实上世纪整个八十年代和九十年代前期,基本
上是重金属的天下,重金属的乐队多如牛毛,出来一个火一个,而且唱片的销量还挺大
。主要的原因俺觉得一是重金属还是比较好听;其二呢,其号召力和煽动性还是巨大的
,比较有名的乐队一般都能得到大多数年轻人的拥戴,这些乐队的灵魂人物甚至能够左
右年轻人的生活方式,像枪炮玫瑰的Axl Rose。给俺印象最深的就是Terminator 2中的
少年时期的John Conner骑着摩托车和他的朋友用手提式录音机播放枪炮玫瑰的Use
Your Illusion II 中的You Could Be mine。在当时看来,只要是听这些乐队的歌就是
一种酷。
提到了枪炮玫瑰,那就先说说它。严格的来说,枪炮玫瑰的音乐应该是朋克和重金属的
混合体,更偏向重金属一点。这个乐队有两个灵魂人物,Axl Rose和Slash,前者是主
唱,钢琴手和作... 阅读全帖 |
|
w****w 发帖数: 521 | 16 搞了两个礼拜,对python有点感觉了。
import math
_expr=lambda x,y,z:"(%s%s%s)"%(x,y,z)
_plus=lambda x,y: (x[0]+y[0],_expr(x[1],"+",y[1]))
_minus=lambda x,y: (x[0]-y[0],_expr(x[1],"-",y[1]))
_rminus=lambda x,y: _minus(y,x)
_mul=lambda x,y: (x[0]*y[0],_expr(x[1],"*",y[1]))
_div=lambda x,y: (y[0]==0 and (0,"err")) or (x[0]/y[0],_expr(x[1],"/",y[1]))
_rdiv=lambda x,y: _div(y,x)
_mod=lambda x,y: (y[0]==0 and (0,"err")) or (x[0]%y[0],"mod(%s,%s)"%(x[1],y[
1]))
_rmod=lambda x,y: _mod(y,x)
def _power(x,y):
try: ret... 阅读全帖 |
|
w****w 发帖数: 521 | 17 搞了两个礼拜,对python有点感觉了。
import math
_expr=lambda x,y,z:"(%s%s%s)"%(x,y,z)
_plus=lambda x,y: (x[0]+y[0],_expr(x[1],"+",y[1]))
_minus=lambda x,y: (x[0]-y[0],_expr(x[1],"-",y[1]))
_rminus=lambda x,y: _minus(y,x)
_mul=lambda x,y: (x[0]*y[0],_expr(x[1],"*",y[1]))
_div=lambda x,y: (y[0]==0 and (0,"err")) or (x[0]/y[0],_expr(x[1],"/",y[1]))
_rdiv=lambda x,y: _div(y,x)
_mod=lambda x,y: (y[0]==0 and (0,"err")) or (x[0]%y[0],"mod(%s,%s)"%(x[1],y[
1]))
_rmod=lambda x,y: _mod(y,x)
def _power(x,y):
try: ret... 阅读全帖 |
|
a****e 发帖数: 9589 | 18 最先想到re,然后是mod(%),range 想的妙(佩服),textwrap 从未接触过(学习
了),其他的从直觉上觉得效率不高,pass了。
写了个测试程序如下:
import timeit
s = "0001001101111111"
def mtimeit(func):
def wrap(*args, **kwargs):
t = timeit.Timer(func)
print func.func_name,
print min(t.repeat(number=1))
return func
return wrap
@mtimeit
def re_func():
import re
return '-'.join(re.findall('\d{4}', s))
@mtimeit
def mod_func():
return ''.join(x if i%4 or i==0 else '-'+x for i,x in enumerate(s))
@mtimeit
de... 阅读全帖 |
|
|
发帖数: 1 | 20 01 class Test1:
02 def __init__(self, x):
03 self.x=x
04 @property
05 def x(self):
06 return self.__x
07 @x.setter
08 def x(self, x):
09 self.__x=x
10 t=Test1(10)
11 t.__x=20
12 print(t.x)
13 print(t.__x)
14
15 class Test2:
16 def __init__(self, x):
17 self.__x=x
18 @property
19 def x(self):
20 return self.__x
21 @x.setter
22 def x(self, x):
23 self.__x=x
24 t=Test2(10)
25 t.__x=20
26... 阅读全帖 |
|
w*******y 发帖数: 60932 | 21 ***All times EST***: These are deals that will be upcoming on Tuesday, 12/21
/10
I'm going to list ***pre-prices before*** the Lightning Deals start.
Remember when the lightning deals start, the prices should be lower than the
listed prices here.
I hope this helps at least one person get the head's up on what they are
looking for
Link:
http://www.amazon.com/gp/goldbox/
Notes: Free shipping available for orders over $25 / free super saving
shipping available for items that are under $25 (you must... 阅读全帖 |
|
D***r 发帖数: 7511 | 22 python最大的好处是写function wrapper方便
相当于函数继承,不用通过类
比如下面的例子
def add_fuck(func):
def wrapper(name, n):
return "fuck " + name
return wrapper
def count_fuck(func):
def wrapper(name, n):
return "%s %d times" %(func(name, n), n)
return wrapper
@count_fuck
@add_fuck
def greet(name, n):
return name
如果执行greet('五毛', 10) 结果就是
fuck 五毛 10 times
数据处理的时候常常需要这种局部修饰 |
|
l****p 发帖数: 397 | 23 确实想不出比mlg(N)更快的算法。这题要在30分钟内做完确实很难,我看了楼主的思路
后还用了近50分钟才写完的……
顺便贴上我的实现(Ruby):
def nearest_nodes root, m, key
node = find_insert root, key
prev = node.prev_node
nex = node.next_node
results = []
m.times do
nearest = nil
if prev and nex
if m-prev.value
nearest = prev
prev = prev.next_node
else
nearest = nex
nex = nex.next_node
end
elsif prev
nearest = prev
prev = prev.prev_node
elsif nex
nearest ... 阅读全帖 |
|
m******t 发帖数: 273 | 24 【 以下文字转载自 Quant 讨论区 】
发信人: myregmit (myregmit), 信区: Quant
标 题: solve integral eq. embeeded with another integral eq.
发信站: BBS 未名空间站 (Sun Mar 23 14:20:18 2014, 美东)
I need to solve an integral equation embedded with another integral equation
by python 3.2 in win7.
There are 2 integral equations.
The code is here:
import numpy as np
from scipy.optimize.minpack import fsolve
from numpy import exp
from scipy.integrate.quadpack import quad
import matplotlib.pyplot as plt
impor... 阅读全帖 |
|
i***h 发帖数: 19 | 25 我也用python寫的,一開始試過各種O(n^2)方法都不行,估計預期是要manacher之類O(
n)的算法;不過我後來用一些trick把它給過了,主要是對於長字串和短字段分別處理
class Solution:
# @return a string
def longestPalindrome(self, s):
if s is None or len(s) == 0:
return ''
def max_palindrome(left, right, min_length):
if right - left < min_length:
return ''
start = left
while left < right:
if s[left] != s[right]:
if right - left < min_length:
... 阅读全帖 |
|
d**********o 发帖数: 279 | 26 没想出怎么用stack, 大牛讲解一下?
"""
Write a iterator to iterate a nested array.
For example, for given array: [1, 2, [3, [4, 5], [6, 7], 8], 9, 10]
call iterator.next() 10 times should return 1,2,3,4,5,6,7,8,9,10.
"""
def traverse(l):
if not l:
return
for i in l:
if isinstance(i, list):
traverse(i)
else:
print i
class NestIterator(object):
def __init__(self, l):
self.l = l
self.cur = -1
self.iterator = None
def next(self):
if self.iterator and s... 阅读全帖 |
|
L********e 发帖数: 159 | 27 还好吧。相当于一个简化版json parser而json parser本身逻辑就很简单,code差不多
这样
def read_object():
read_start_object()
while (cursor.value != '}'):
field = read_field_name():
if field == 'name':
read_string_value()
elif field == 'children':
read_array()
read_end_object()
def read_array():
read_start_array()
while (cursor.value != ']'):
read_object()
read_end_array()
def read_field_name():
name = read_string_value()
read_colon()
re... 阅读全帖 |
|
发帖数: 1 | 28 没那么简单。
s1= "abc def def def efg efg hij hij xyz"
s2 = "ab def def hij klm klm klm"
返回 abc, efg, xyz |
|
Y*****s 发帖数: 342 | 29
quality of
point of view (breeze, msee, bison, etc)
Wrong prediction:
result,QB DEF RB WR TE
Correct preditcion:
K
much better DEF. this should be a big margin win. (fwiw, froger
hasn't even adjusted his lineups yet)
Wrong prediction:
result,QB WR RB TE K DEF
correct prediction:none
Wrong prediction:result,QB RB,TE
correct prediction:DEF,K
wrong prediction:result,QB WR,DE, TE,K,RB
correct prediction:none
wrong prediction:result,K,RB,WR
correct prediction: TE,DEF,QB
wrong predicti |
|
b*******o 发帖数: 832 | 30 SBI NFL皇马 def 弃妇
SBX NFL毛片米兰 def NFL利物浦
SBXX NFL诺丁汉森林 def NFL巴洗隆拿(ARod this is not a trolling)
SBXXX 利物浦 def 米兰
SBXL NFL米兰 def NFL车路士
这里面的参赛队现在也都破处了. SBL会不会出一个新警察? (Sorry Cubs but I think
your name will be mentioned again.) |
|
g****z 发帖数: 90 | 31 新人完全不懂。也不折腾。版上说DD挺好。下面的该选那个? 当然,也欢迎推荐别的牌
子。多谢了。
1. Dd M4 V3 556 nato 16" 10r(mid) Bb Ca $1738
2. Dd V5 Lw 556nato 16" Blk 10rd Bb Ca $1633
3. Dd V5 556nato 16" Grey 10rd Bb Ca $1757
4. Dd V9 556nato 16" Blk 10rd Bb Ca $1633
5. Dd V9 556nato 16" Blk 10rd Bb Lw Ca $1633
6. Daniel Def. M4 Carbine V11-cc-Lw 556nato 16" Bb Ca $1548
7. Daniel Def. M4 Carbine V11 Grey 5.56x45 16" 30rd Keymod $1643
8. Daniel Def. M4 Carbine V11-msp 5.56x45 16" 30rd Keymod $1643
9. Daniel Def. M4 ... 阅读全帖 |
|
s****y 发帖数: 958 | 32 1. USC (52) 2-0 1,611 1
Last game: Def. Colorado State 49-0 (Sep. 11)
This week: at BYU (1-1)
2. Oklahoma (10) 2-0 1,552 2
Last game: Def. Houston 63-13 (Sep. 11)
This week: vs. Oregon (0-1)
3. Georgia (3) 2-0 1,478 3
Last game: Def. South Carolina 20-16 (Sep. 11)
This week: vs. Marshall (0-2)
4. Miami 1-0 1,398 5
Last game: Def. Florida State 16-10 (Sep. 10)
This week: vs. Louisiana Tech (2-0)
5. LSU 2-0 1,344 6
Last game: Def. Arkansas State 53-3 (Sep. 11)
This w |
|
f*n 发帖数: 1019 | 33 1. USC (46) 4-0 1,507 1
Last game: Def. Stanford 31-28 (Sep. 25)
This week: vs. No. 10 California (3-0)
2. Oklahoma (12) 4-0 1,462 2
Last game: Def. Texas Tech 28-13 (Oct. 2)
This week: vs. No. 5 Texas (4-0)
3. Georgia (1) 4-0 1,398 3
Last game: Def. No. 13 LSU 45-16 (Oct. 2)
This week: vs. No. 8 Tennessee (3-1)
4. Miami (2) 4-0 1,347 4
Last game: Def. Georgia Tech 27-3 (Oct. 2)
Next week: vs. No. 22 Louisville (Oct. 14)
5. Texas 4-0 1,283 5
Last game: Def. Baylor 44-14 (Oct. 2)
This w |
|
f*******8 发帖数: 3612 | 34 这是一个将RFC 文件转换成 kindle格式的程序,
来自:
https://github.com/pingwin/RFC-2-Kindle
我是windows上的python 2.71, 运行完全仿照该网站的要求
结果出来是找不到font MONOSPACE, 不知道MONOspace是不是个字体库或别的什么。
running output:
D:\>rfctxt2kindlehtml.py -i rfc791.txt -o rfc791.html && ./ki
ndlegen rfc791.html
Unable to find font: /usr/share/cups/fonts/Monospace
Convert IETF RFC TXT file to HTML for kindlegen
-h --help This message
-v verbosity
-i --input input file
-o --output output file
-f --font font file to use for monospace ... 阅读全帖 |
|
S*******s 发帖数: 13043 | 35 I got an error if I want to run test.py:
@singleton
NameError: name 'singleton' is not defined
if I combine the two files, it would be fine.
what is right way to import decorator?
#in module Singleton.py
def singleton(theClass):
""" decorator for a class to make a singleton out of it """
classInstances = {}
def getInstance(*args, **kwargs):
""" creating or just return the one and only class instance.
The singleton depends on the parameters used in __init__ """... 阅读全帖 |
|
s****0 发帖数: 117 | 36 贴一个scala的。正在学习,书还没完全看完。初学乍练,多多指教
package myTest
import scala.collection.mutable.Map
import scala.collection.mutable.Stack
class Test3(lst: Array[Int], target: Int, all: Boolean) {
def solve() = {
for (inst <- genInstr(lst.length); op <- ops(lst.length - 1); l <- lst.
permutations) {
val rst = exec(inst, op, l);
if (rst == target) {
println(inst + ", " + op)
}
}
}
def genInstr(n: Int): IndexedSeq[String] = {
if (n == 1)
return Array("g");
for ... 阅读全帖 |
|
m********5 发帖数: 17667 | 37 因为import, dot操作等消耗的时间远超过其他步骤
所以我觉得有必要修改一下,直接把reptfda用在测试func中
import re
rept=re.compile('\d{4}')
reptfda=rept.findall
为了 eliminate global var lookup overhead 的影响,应该多尝试几次 number=1应
该是不行的。
修改了一下:
def testAthome2(s,niter):
import re
rept=re.compile('\d{4}')
reptfda=rept.findall
def mtimeit(func):
def wrap(*args, **kwargs):
t = timeit.Timer(func)
print func.func_name,
print min(t.repeat(number=niter))
return func
return ... 阅读全帖 |
|
p**o 发帖数: 3409 | 38 用类就行了。java和python都类似。
class Node (object):
""" Node for a linked list. """
def __init__ (self, value, next=None):
self.value = value
self.next = next
class LinkedList (object):
""" Linked list ADT implementation using class.
A linked list is a wrapper of a head pointer
that references either None, or a node that contains
a reference to a linked list.
"""
def __init__ (self, iterable=()):
self.head = None
for x in iterabl... 阅读全帖 |
|
g****t 发帖数: 31659 | 39 我从未写过一行Continuation。
我理解的Turing的1936 paper数理逻辑知识,能不能落到实处?刚才花了一小时python。
作为一个无名散户,我愿意把自己的错误过程,polish的过程分享给大家批评。
这程序的目的是不用loop index把一个函数g调用n次。
实现用continuation消除loop的转换。
我想我证实了,从Turing 1936 paper出发,一般人都可以"invent" continuation。
def g(x):
print(x+1)
return x+1
def F(n,S):
if n == 0:
t = S(0)
else:
F(n-1,( lambda x:S(S(x)) ))
#F(3,g) called g 2^x times
def F1(n,S):
if n == 0:
t = S(0)
else:
f = lambda x:g(x)
# we had to use g that is not... 阅读全帖 |
|
m******t 发帖数: 273 | 40 【 以下文字转载自 Quant 讨论区 】
发信人: myregmit (myregmit), 信区: Quant
标 题: solve integral eq. embeeded with another integral eq.
发信站: BBS 未名空间站 (Sun Mar 23 14:20:18 2014, 美东)
I need to solve an integral equation embedded with another integral equation
by python 3.2 in win7.
There are 2 integral equations.
The code is here:
import numpy as np
from scipy.optimize.minpack import fsolve
from numpy import exp
from scipy.integrate.quadpack import quad
import matplotlib.pyplot as plt
impor... 阅读全帖 |
|
m******t 发帖数: 273 | 41 I need to solve an integral equation embedded with another integral equation
by python 3.2 in win7.
There are 2 integral equations.
The code is here:
import numpy as np
from scipy.optimize.minpack import fsolve
from numpy import exp
from scipy.integrate.quadpack import quad
import matplotlib.pyplot as plt
import sympy as syp
lb = 0
def integrand2(x, a):
print("integrand2 called")
return x**(a-1) * exp(-x)
def integrand1(x, b, c):
print(... 阅读全帖 |
|
D******n 发帖数: 2836 | 42 the log syntax definition in sas.vim is minimal even if it works.
here is how to make log look nice.
1) create ~/.vim/syntax/log.vim
syn match sasNumber "-\=\<\d*\.\=[0-9_]\>"
syn match sasNote "\s*NOTE:.*" contains=sasNumber
syn match sasWarn "\s*WARNING:.*" contains=sasNumber
syn match sasError "\s*ERROR.*" contains=sasNumber
syn region sasEp start="^\s\+_$" end="^\s\+\d\+$" contains=sasNumber
hi sNote term=NONE cterm=bold ctermfg=Blue ctermbg=Black gui=bold guifg=Blue
guibg=black
hi sWarn ter... 阅读全帖 |
|
m******t 发帖数: 273 | 43 【 以下文字转载自 Quant 讨论区 】
发信人: myregmit (myregmit), 信区: Quant
标 题: solve integral eq. embeeded with another integral eq.
发信站: BBS 未名空间站 (Sun Mar 23 14:20:18 2014, 美东)
I need to solve an integral equation embedded with another integral equation
by python 3.2 in win7.
There are 2 integral equations.
The code is here:
import numpy as np
from scipy.optimize.minpack import fsolve
from numpy import exp
from scipy.integrate.quadpack import quad
import matplotlib.pyplot as plt
impor... 阅读全帖 |
|
h*******e 发帖数: 5550 | 44 彭云大获全胜啊!
Final Results :
Men's Singles:
Sattawat Pongnairat (#1 Seed) def. Hock Lai Lee (#3/4 Seed) 21-16,21-15
Women's Singles:
Bo Rong (#1 Seed) def. Sharon Ng 21-12,21-17
Men's Doubles:
Halim Haryanto Ho / Chandra Kowi (#3/4 Seed) def. Howard Bach / Phillip Chew
21-17,21-19
Women's Doubles:
Joo Hyun Lee / Yun Peng (#2 Seed) def. Daphne Ng / Bo Rong 21-10,21-11
Mixed Doubles:
Holvy De Pauw / Yun Peng def. Kyle Emerick / Kuei Ya Chen (#3/4 Seed) 21-9,
21-15 |
|
发帖数: 1 | 45 这种特性在只要支持higher order function的语言面前根本不需要什么@这种花里胡哨
的语法糖
: python最大的好处是写function wrapper方便
: 相当于函数继承,不用通过类
: 比如下面的例子
: def add_fuck(func):
: def wrapper(name, n):
: return "fuck " name
: return wrapper
: def count_fuck(func):
: def wrapper(name, n):
: return "%s %d times" %(func(name, n), n)
|
|
l**********g 发帖数: 6198 | 46 hitdollar没在
你马甲太多了,也不知道是在上哪一个。。。。
"guess the number"我有个地方卡住了
need help~~~
别的都可以,就是那个还有几次可以猜,插不进。。。。
单独这个函数我会写,不过不知道在哪里插,老是报错啊
一个多小时就要交了,实在想不出来
如果你在1点前看到了,贴出来给我参考下?~~~ 哈哈(我明早起来删掉,不会占用版
面的)
帖子里回复,领导在旁边,不敢一直上账号lol
我的code如下:
import simplegui
import random
import math
# initialize global variables used in your code
secret_number=0
guess_number=0
num_range=100
# define event handlers for control pane
def init():
global guess_number
print "Guess was",guess_number
# button that c... 阅读全帖 |
|
h*******r 发帖数: 928 | 47 我先把我的贴在这里,你运行看看结果,有什么启发,我再看看你的问题。
# template for "Guess the number" mini-project
# input will come from buttons and an input field
# all output for the game will be printed in the console
import simplegui
import random
import math
# initialize global variables used in your code
num_range = 100
remaining_guess = 7
secret_number = 0
user_input = 0
def init():
global secret_number, num_range, remaining_guess
secret_number = random.randrange(0, num_range)
if num_range == 100:
rem... 阅读全帖 |
|
m******k 发帖数: 92 | 48 今天周四, 收到两张TRAFFIC CITATION, 每张罚款119.50. 一张的罪名是FOLLOW TOO
CLOSE, 另一张罪名是FAIL TO PROVIDE INFO/AID. COURT DATE 7月6号.
其中一个REMARKS:
TO WIT THE DEF. DID OPERATE HIS VEHICLE AT THE ABOVE LOCATION AND DID STRIKE
THE REAR BUMPER OF ANOTHER VEHICLE. THE DEF THEN LEFT THE SCENE OF THE
ACCIDENT AND FAILED TO PROVIDE PROPER INFORMATION.
另一张上他写的是:
TO WIT THE DEF. DID OPERATE HIS VEHICLE AT THE ABOVE LOCATION AND DID FAIL
TO REMAIN A SAFE DISTANCE FROM THE VEHICLE IN FRONT OF HIS. DEF. WAS UNABLE
TO STOP IN TIM |
|
d*******l 发帖数: 338 | 49 来自主题: JobHunting版 - 求助一算法 这种数字和的问题卷积确实非常好使,鉴于k不一定是10的整次方,具体做起来还要麻
烦一些。下面是一个python的实现:
def conv(a, b):
r = [];
n = len(a);
m = len(b);
a += [0] * m;
b += [0] * n;
for i in xrange(n+m):
t = 0;
for j in xrange(i+1):
t += a[j]*b[i-j];
r.append(t);
return r;
def sum(n):
ret = 0
while(n > 0):
ret += n % 10;
n /= 10;
return ret;
def addV(a, b):
l = min(len(a), len(b));
for i in xrange(l):
a[i] += b[i];
def solve(k... 阅读全帖 |
|