在如何使用Python表达二进制文字的基础上,我正在考虑以明智,直观的方式来实现以基础2形式显示整数的编程101板栗.这是我提出的最好的,但我想用更好的算法替换它,或者至少一个应该具有尖叫 - 快速性能的算法.
def num_bin(N, places=8):
def bit_at_p(N, p):
''' find the bit at place p for number n '''
two_p = 1 << p # 2 ^ p, using bitshift, will have exactly one
# bit set, at place p
x = N & two_p # binary composition, will be one where *both* numbers
# have a 1 at that bit. this can only happen
# at position p. will yield two_p if N has a 1 …Run Code Online (Sandbox Code Playgroud) 我对学习C感兴趣.我读过K&R,甚至在R和Python中做过一些简单的C扩展工作.使用C做更实质的事情有什么值得的项目想法?任何好的在线资源,类似于Dive Into Python?特别是,资源专注于已经知道正在尝试学习C的新语言的程序员(提到诸如"在C中询问数组的长度是无意义的,你懒惰的Pythonista").
我的背景:
数学/统计学,Python,R中的日常编程,主要围绕自然语言处理,算法等.
因此,Google App Engine看起来不会很快包含Python Imaging Library .有一个图像api,但它很微不足道,不足以满足我的需要.
我想知道什么只有Python(没有C扩展)可以替代Image.paste和ImageDraw模块.我不想自己写,但这是一个选择.我也对其他解决方案持开放态度,例如"在其他地方进行处理,然后通过api调用",如果它们不是太难看的话.(为了记录,我刚刚建议的解决方案对我来说似乎很难看.)
其他人如何得到这个?
(我不是很喜欢GAE,只是探索,这看起来像是我的应用程序的交易破坏者.)
笔记:
对我来说,裁剪,调整大小是不够的.特别是我需要
因此,当某事物的长度接近1 << 32(int的大小)时,cPython(2.4)会有一些有趣的行为.
r = xrange(1<<30)
assert len(r) == 1<<30
Run Code Online (Sandbox Code Playgroud)
很好,但是:
r = xrange(1<<32)
assert len(r) == 1<<32
ValueError: xrange object size cannot be reported`__len__() should return 0 <= outcome
Run Code Online (Sandbox Code Playgroud)
Alex的wowrange也有这种行为. wowrange(1<<32).l很好,但 len(wowrange(1<<32))很糟糕.我猜这里有一些浮点行为(被视为负面)行动.
(我的具体应用是,random.sample(xrange(1<<32),ABUNCH))如果人们想直接解决这个问题!)
高级:我能做到这一点order by,group by基于sum
任何更快吗?(PG 8.4,fwiw.,在非小桌子上......想想O(数百万行))
假设我有一个这样的表:
Table "public.summary"
Column | Type | Modifiers
-------------+-------------------+------------------------------------------------------
ts | integer | not null default nextval('summary_ts_seq'::regclass)
field1 | character varying | not null
otherfield | character varying | not null
country | character varying | not null
lookups | integer | not null
Indexes:
"summary_pk" PRIMARY KEY, btree (ts, field1, otherfield, country)
"ix_summary_country" btree (country)
"ix_summary_field1" btree (field1)
"ix_summary_otherfield" btree (otherfield)
"ix_summary_ts" btree (ts)
Run Code Online (Sandbox Code Playgroud)
我想要的查询是:
select summary.field1,
summary.country, …Run Code Online (Sandbox Code Playgroud) 目标:对于某些匹配模式P的库,按原样webpack发出/编译require语句.
例:
假设我有一个mylib我想要通过的as-is,所以需要在运行时工作.
和这样的代码.
var b = require("./some.stuff.that.webpack.should.inline");
a = require('mylib/should/stay/a/Require');
我想要看起来像这样的输出
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
a = __webpack_require__(1);
/***/ },
/* 1 */
/***/ function(module, exports) {
module.exports = require('mylib/should/stay/a/Require');
Run Code Online (Sandbox Code Playgroud)
我知道插件可以做到这一点,但我无法拦截正确的事件/理解插件文档
到目前为止尝试过:1 external....这假定定义在别的地方2. IgnorePlugin给出了webpackMissingModule......与我想要的相反.
基于"在Python中用空格分割字符串",它使用shlex.split智能地分割带引号的字符串,我将有兴趣听到非显而易见的标准库函数解决的其他常见任务.
如果这变成了本周的模块,那也没关系.
所以,我在Python中遇到了一些精确问题.
我想计算这样的函数:
P(x,y) = exp(-x)/(exp(-x) + exp(-y))
Run Code Online (Sandbox Code Playgroud)
其中x和y可能> 1000.Python的math.exp(-1000)(至少在2.6中!)没有足够的浮点精度来处理这个问题.
(另外,我对标题持开放态度!对于这个问题,我想不出一个好的!)
我有许多(数千!)数据文件,这些数据文件采用标准的基于字段的格式(想象制表符分隔,每行中每个文件中的相同字段).我正在讨论使这些数据可用/可搜索的各种方法.(一些选项包括RDBMS,NoSQL的东西,使用grep/awk和朋友等).
特别是,一个吸引我的想法是以某种方式"索引"文件.由于这些文件是只读的(和静态的),我想象一些包含二叉树的持久文件(每个索引字段一个,就像在其他数据存储中一样).我对如何做到这一点持开放态度,或者听说这只是疯了.大多数情况下,我最喜欢的搜索引擎并未为此提供任何预先解决的解决方案.
我意识到这有点不合理,欢迎解决方案.
(所有这些都是基于我的观察和测试,但我愿意纠正)
BDB
RDBMS中
胜利:
损失:
我正在研究Orange,并且在 OSX (10.6.5) 中,菜单栏名称是“Python”而不是橙色,我得到了这个 nit。这是一个 python/qt 应用程序。我需要改变什么?
澄清:
我的信息.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>YOORANGE</string>
<key>CFBundleExecutable</key>
<string>Orange</string>
<key>CFBundleIconFile</key>
<string>orange.icns</string>
<key>CFBundleIdentifier</key>
<string>si.ailab.Orange</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Orange</string>
<key>CFBundleGetInfoString</key>
<string>Orange, component-based data mining software</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>Orng</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>ows</string>
</array>
<key>CFBundleTypeName</key>
<string>Orange Canvas Schema</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>OWSf</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>schema.icns</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSIsAppleDefaultForType</key>
<true/>
</dict>
</array>
</dict> …Run Code Online (Sandbox Code Playgroud)