它似乎是某种横向连接,但我在网上找不到任何文档.这是一个最小的工作示例:
In [1]: from numpy import c_
In [2]: a = ones(4)
In [3]: b = zeros((4,10))
In [4]: c_[a,b]
Out[4]:
array([[ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
Run Code Online (Sandbox Code Playgroud) def save_file(self, outputfilename = self.image_filename):
self.file.read(outputfilename)
....
Run Code Online (Sandbox Code Playgroud)
NameError: name 'self' is not defined在第一行给出.似乎Python不接受它.如何重写代码以免引发异常?
当我从改变工作组大小16来32或更大的东西,我得到一个CL_INVALID_WORK_GROUP_SIZE错误.matrix_size是64.
localWorkSize[0] = groupsize;
localWorkSize[1] = localWorkSize[0];
globalWorkSize[0] = matrix_size;
globalWorkSize[1] = globalWorkSize[0];
Run Code Online (Sandbox Code Playgroud)
首先,我检查了clEnqueueNDRangeKernel的文档,其中列出了四(5)种不同的原因CL_INVALID_WORK_GROUP_SIZE,但我认为它们不适用.请检查我的结论.(我希望你不介意我的QA风格)
Q CL_INVALID_WORK_GROUP_SIZE if local_work_size is specified and number of work-items specified by global_work_size is not evenly divisable by size of work-group given by local_work_size
甲 64%32 = 0
Q or does not match the work-group size specified for kernel using the __attribute__((reqd_work_group_size(X, Y, Z))) qualifier in program source.
答: 据我了解帮助,我没有使用 …
我想转换a = [1,2,3,4,5]成a_string = "1 2 3 4 5".真正的numpy数组相当大(50000x200)所以我认为使用for loops太慢了.
这是什么意思?
我的函数从python/c库中获取两个numpy数组.在该函数调用之后,我打开调试器来查找错误,所以我添加了一行来查看两个numpy数组.
import pdb; pdb.set_trace()
Run Code Online (Sandbox Code Playgroud)
但是对于其中一个arrays pdb唯一返回消息的值*** Newest frame
PDB输出:
(Pdb) type(d)
<type 'numpy.ndarray'>
(Pdb) type(f)
<type 'numpy.ndarray'>
(Pdb) f.shape
(3, 3, 17856)
(Pdb) d[0].shape
*** Newest frame
(Pdb) d[0]
*** Newest frame
Run Code Online (Sandbox Code Playgroud) 如果我使用pylint(通过sublimerlinter),我收到以下警告消息:
W602 deprecated form of raising exception
这个我如何在我的代码中使用异常:
if CONDITION == True:
raise ValueError, HELPING_EXPLANATION
Run Code Online (Sandbox Code Playgroud) 我正在使用boto和python以及amazon s3.
如果我使用
[key.name for key in list(self.bucket.list())]
然后我得到所有文件的所有密钥.
mybucket/files/pdf/abc.pdf
mybucket/files/pdf/abc2.pdf
mybucket/files/pdf/abc3.pdf
mybucket/files/pdf/abc4.pdf
mybucket/files/pdf/new/
mybucket/files/pdf/new/abc.pdf
mybucket/files/pdf/2011/
Run Code Online (Sandbox Code Playgroud)
什么是最好的方式
1. either get all folders from s3
2. or from that list just remove the file from the last and get the unique keys of folders
Run Code Online (Sandbox Code Playgroud)
我想这样做
set([re.sub("/[^/]*$","/",path) for path in mylist]
Run Code Online (Sandbox Code Playgroud) 编译函数时theano,可以通过指定更新共享变量(比如X)updates=[(X, new_value)].现在我试图只更新共享变量的子集:
from theano import tensor as T
from theano import function
import numpy
X = T.shared(numpy.array([0,1,2,3,4]))
Y = T.vector()
f = function([Y], updates=[(X[2:4], Y)] # error occur:
# 'update target must
# be a SharedVariable'
Run Code Online (Sandbox Code Playgroud)
代码将引发错误"更新目标必须是SharedVariable",我猜这意味着更新目标不能是非共享变量.那么有没有办法编译一个函数只是udpate共享变量的子集?
如果知道列表的长度和数组的大小,那么将numpy数组列表合并到一个数组中的最快方法是什么?
我尝试了两种方法:
merged_array = array(list_of_arrays)从Python化的方式来从numpy的阵列的列表创建numpy的阵列和
vstack
您可以看到vstack更快,但由于某种原因,第一次运行比第二次运行时间长三倍.我假设这是由(缺少)预分配引起的.那么我将如何为数组预分配vstack?或者你知道更快的方法吗?
谢谢!
[UPDATE]
我(25280, 320)不想要(80, 320, 320)哪种方式,不merged_array = array(list_of_arrays)适合我.谢谢Joris指出这个!
输出:
0.547468900681 s merged_array = array(first_list_of_arrays)
0.547191858292 s merged_array = array(second_list_of_arrays)
0.656183958054 s vstack first
0.236850976944 s vstack second
Run Code Online (Sandbox Code Playgroud)
码:
import numpy
import time
width = 320
height = 320
n_matrices=80
secondmatrices = list()
for i in range(n_matrices):
temp = numpy.random.rand(height, width).astype(numpy.float32)
secondmatrices.append(numpy.round(temp*9))
firstmatrices = list()
for i in …Run Code Online (Sandbox Code Playgroud) 该theano安装文档状态,即theano将作为默认使用BLAS库从numpy的,如果"BLAS库可为动态加载库".这似乎不适用于我的机器,请参阅错误消息.
如果您需要更多信息,请说明!
错误信息
We did not found a dynamic library into the library_dir of the library we use for blas. If you use ATLAS, make sure to compile it with dynamics library.
/usr/bin/ld: cannot find -lblas
附录
该theano除其他事项外库的需求与NumPy和BLAS库.如果你sudo apt-get install python-numpy python-scipy在Ubuntu下安装它,我认为numpy带有BLAS .
这是文件列表 /usr/lib64/python2.6/dist-packages/scipy/lib/blas
cblas.so info.py __init__.py scons_support.py setup.py
fblas.so info.pyc __init__.pyc scons_support.pyc setup.pyc
setupscons.py test
setupscons.pyc
Run Code Online (Sandbox Code Playgroud)
这是输出distutils.__config__.show()如下
blas_info:
libraries = ['blas']
library_dirs = ['/usr/lib64'] …Run Code Online (Sandbox Code Playgroud)