例如,如果我们有一个numpy数组A,并且我们想要一个具有相同元素的numpy数组B.
以下(见下文)方法有什么区别?什么时候分配额外的内存,什么时候不分配?
B = AB[:] = A(和B[:]=A[:]?一样)numpy.copy(B, A)我正在通过http://www.mypythonquiz.com工作,问题#45要求输出以下代码:
confusion = {}
confusion[1] = 1
confusion['1'] = 2
confusion[1.0] = 4
sum = 0
for k in confusion:
sum += confusion[k]
print sum
Run Code Online (Sandbox Code Playgroud)
输出是6,因为密钥1.0替换1.这对我来说有点危险,这是一个有用的语言功能吗?
我正在尝试用我的项目来构建
g++ -O0 -g -fsanitize=address -fno-omit-frame-pointer
Run Code Online (Sandbox Code Playgroud)
但是会遇到很多错误:
/home/user/libs/opencv/include/opencv2/core/mat.hpp:715: undefined reference to `__asan_report_load8'
Run Code Online (Sandbox Code Playgroud)
如何使用AddressSanitize支持编译项目?
我的gcc版本是4.8.4.
是否可以通过apt-get安装openblas sudo apt-get install openblas-dev?
好像在ubuntu 14.04上找不到它.
sudo apt-get install openblas-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package openblas-dev
Run Code Online (Sandbox Code Playgroud) 当我./gradlew从项目文件夹运行时,我得到:
./gradlew\nThe operation couldn\xe2\x80\x99t be completed. Unable to locate a Java Runtime.\nPlease visit http://www.java.com for information on installing Java.\nRun Code Online (Sandbox Code Playgroud)\n与java相同:
\nwhich java\n/usr/bin/java\n\n/usr/bin/java\nThe operation couldn\xe2\x80\x99t be completed. Unable to locate a Java Runtime.\nPlease visit http://www.java.com for information on installing Java.\nRun Code Online (Sandbox Code Playgroud)\n我在Android studio中安装了JDK,似乎它安装在~/Library/Android/sdk/sources/android-28
设置export JAVA_HOME=/Users/mrgloom/Library/Android/sdk/sources/android-28/或export JAVA_HOME=/Users/mrgloom/Library/Android/sdk产生错误,例如:
ERROR: JAVA_HOME is set to an invalid directory: /Users/mrgloom/Library/Android/sdk/sources/android-28/\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\n …Run Code Online (Sandbox Code Playgroud) 当我gcc在Cygwin中使用时,我收到俄语的错误消息,例如,如下所示:
$ gcc -Wall kmeans.c -o kmeans
kmeans.c:260:1: ??????????????: ??????? ?????????? ???????? ?????? ???????? ? ???????????? ???? [-Woverflow]
size_t used_size = ULLONG_MAX; // size of each file used, binary file only
Run Code Online (Sandbox Code Playgroud)
但是我更喜欢用英语工作.因此,如何永久更改Cygwin终端中使用的语言?
我正在尝试编写自定义丢失函数:我想应用于categorical_crossentropy输入向量的部分然后求和.
假设y_true,y_pred是1D向量.
码:
def custom_loss(y_true, y_pred):
loss_sum= 0.0
for i in range(0,y_true.shape[0],dictionary_dims):
loss_sum+= keras.backend.categorical_crossentropy(y_true[i*dictionary_dims:(i+1)*dictionary_dims], y_pred[i*dictionary_dims:(i+1)*dictionary_dims])
return loss_sum
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
for i in range(0,y_true.shape[0],dictionary_dims):
TypeError: __index__ returned non-int (type NoneType)
Run Code Online (Sandbox Code Playgroud)
那么如何访问输入张量的形状来获得张量的子集呢?
更新: 还尝试直接通过tensorflow写丢失:
def custom_loss_tf(y_true, y_pred):
print('tf.shape(y_true)',tf.shape(y_true)) #
print('type(tf.shape(y_true))',type(tf.shape(y_true))) #
sys.exit()
loss_sum= 0.0
for i in range(0,y_true.shape[0],dictionary_dims):
loss_sum+= keras.backend.categorical_crossentropy(y_true[i*dictionary_dims:(i+1)*dictionary_dims], y_pred[i*dictionary_dims:(i+1)*dictionary_dims])
return loss_sum
Run Code Online (Sandbox Code Playgroud)
输出:
tf.shape(y_true) Tensor("Shape:0", shape=(2,), dtype=int32)
type(tf.shape(y_true)) <class 'tensorflow.python.framework.ops.Tensor'>
Run Code Online (Sandbox Code Playgroud)
不确定是什么shape=(2,)意思,但这不是我所期待的,因为model.summary()显示最后一层是(None, 26):
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_1 (InputLayer) (None, 80, …Run Code Online (Sandbox Code Playgroud) 这里使用hdf5的矩阵乘法我使用hdf5(pytables)进行大矩阵乘法,但我很惊讶因为使用hdf5它的工作速度更快,然后在RAM中使用普通的numpy.dot和存储矩阵,这种行为的原因是什么?
也许在python中有一些更快的矩阵乘法函数,因为我仍然使用numpy.dot进行小块矩阵乘法.
这是一些代码:
假设矩阵可以适合RAM:在矩阵10*1000 x 1000上进行测试.
使用默认numpy(我认为没有BLAS lib).普通的numpy数组在RAM中:时间9.48
如果A,B在RAM中,C在磁盘上:时间1.48
如果磁盘上的A,B,C:时间372.25
如果我使用numpy与MKL结果是:0.15,0.45,43.5.
结果看起来很合理,但我仍然不明白为什么在第一种情况下块乘法更快(当我们将A,B存储在RAM中时).
n_row=1000
n_col=1000
n_batch=10
def test_plain_numpy():
A=np.random.rand(n_row,n_col)# float by default?
B=np.random.rand(n_col,n_row)
t0= time.time()
res= np.dot(A,B)
print (time.time()-t0)
#A,B in RAM, C on disk
def test_hdf5_ram():
rows = n_row
cols = n_col
batches = n_batch
#using numpy array
A=np.random.rand(n_row,n_col)
B=np.random.rand(n_col,n_row)
#settings for all hdf5 files
atom = tables.Float32Atom() #if store uint8 less memory?
filters = tables.Filters(complevel=9, complib='blosc') # tune parameters
Nchunk = 128 # ?
chunkshape = (Nchunk, …Run Code Online (Sandbox Code Playgroud) 我正在阅读有关使用CNN(卷积神经网络)进行物体检测的论文.
以下是关于接受领域的引用:
The pool5 feature map is 6x6x256 = 9216 dimensional. Ignoring boundary effects, each pool5 unit has a receptive field of 195x195 pixels in the original 227x227 pixel input. A central pool5 unit has a nearly global view,
while one near the edge has a smaller, clipped support.
Run Code Online (Sandbox Code Playgroud)
我的问题是:
我正在尝试遵循这些说明
sudo apt-get install python-pip python-dev
sudo pip install tensorflow
user@user-VirtualBox:~$ sudo pip install tensorflow
Downloading/unpacking tensorflow
Could not find any downloads that satisfy the requirement tensorflow
Cleaning up...
No distributions at all found for tensorflow
Storing debug log for failure in /home/user/.pip/pip.log
Run Code Online (Sandbox Code Playgroud)
这是pip日志:
user@user-VirtualBox:~$ cat /home/user/.pip/pip.log
------------------------------------------------------------
/usr/bin/pip run on Thu Jan 26 17:25:02 2017
Downloading/unpacking tensorflow
Getting page https://pypi.python.org/simple/tensorflow/
URLs to search for versions for tensorflow:
* https://pypi.python.org/simple/tensorflow/
Analyzing links from page https://pypi.python.org/simple/tensorflow/
Skipping https://pypi.python.org/packages/00/16/c8ba385fc6511ca362f32326cd1d6a99bbbabbc8341607ff70c290e0be7b/tensorflow-0.12.1-cp34-cp34m-manylinux1_x86_64.whl#md5=981c0a406eb9865423b11c03b489040d (from https://pypi.python.org/simple/tensorflow/) …Run Code Online (Sandbox Code Playgroud)