小编Jas*_*son的帖子

为什么objgraph不能捕获np.array()的增长?

看代码:

import objgraph
import numpy as np
objgraph.show_growth()
j = 20
y = []
for i in range(5):
    for l in range(j):
        y.append(np.array([np.random.randint(500),np.random.randint(500)]))
    print 'i:',i
    objgraph.show_growth()
    print '___'
    #objgraph.show_most_common_types(limit=100)
    j += 1
Run Code Online (Sandbox Code Playgroud)

结果是:

i: 1
wrapper_descriptor 1596 +3
weakref 625 +1
dict 870 +1
method_descriptor 824 +1
i: 2
i: 3
i: 4
Run Code Online (Sandbox Code Playgroud)

对于2,3和4时代,它没有显示任何增长.但它应该表明numpy.array的数量增长

python memory-leaks numpy memory-leak-detector objgraph

3
推荐指数
1
解决办法
251
查看次数

numpy 比像 eigen 这样的 C++ 线性代数库慢吗?

我用它来实现神经网络。我更喜欢NumPy,因为用Python准备数据更方便;但是,我担心 NumPy 不如 C++ 库快。

c++ numpy machine-learning linear-algebra neural-network

2
推荐指数
2
解决办法
4526
查看次数

如何编写一个程序,使用9到1的数字来获取2016年的所有方法?

您可以在9 8 7 6 5 4 3 2之间添加任何运算符(包括括号和+ - */**).例如, 98*76-5432*1=2016 9*8*7*(6+5-4-3)*(2-1)=2016

我写了一个像这样的程序

from __future__ import division
s = ['+','-','*','/','','(',')']

def calc(s):
    a=s.split()
    return eval(''.join(a))
a=['','9','','8','','7','','6','','5','','4','','3','','2','','1.','']

def test(tmp):
    if tmp == 20:
        try:
            z = eval(''.join(a))
            if z == 2016:
                print ''.join(a)
        except:
            pass
        return
    for i in s:
        #print a
        a[tmp] = i
        test(tmp+2)
for j in s:
    a[0] = j
    test(2)
Run Code Online (Sandbox Code Playgroud)

但这是不对的,因为数字之间可能存在多个运算符.

python algorithm math

1
推荐指数
1
解决办法
145
查看次数