在这个问题,有人建议意见,我应该不会投的结果malloc
,即
int *sieve = malloc(sizeof(int) * length);
Run Code Online (Sandbox Code Playgroud)
而不是:
int *sieve = (int *) malloc(sizeof(int) * length);
Run Code Online (Sandbox Code Playgroud)
为什么会这样呢?
我遇到过这个:
item = someSortOfSelection()
if item in myList:
doMySpecialFunction(item)
Run Code Online (Sandbox Code Playgroud)
但有时它不适用于我的所有项目,就好像它们在列表中未被识别一样(当它是一个字符串列表时).
这是在列表中找到一个项目的最"Python化"的方式:if x in l:
?
When plotting heatmaps with seaborn (and correlation matrices with matplotlib) the first and the last row is cut in halve. This happens also when I run this minimal code example which I found online.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
data = pd.read_csv('https://raw.githubusercontent.com/resbaz/r-novice-gapminder-files/master/data/gapminder-FiveYearData.csv')
plt.figure(figsize=(10,5))
sns.heatmap(data.corr())
plt.show()
Run Code Online (Sandbox Code Playgroud)
The labels at the y axis are on the correct spot, but the rows aren't completely there.
A few days ago, it work as intended. Since then, I …
我按照CPU的指示在我的Ubuntu 15.10机器上安装了TensorFlow:
$ pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
Run Code Online (Sandbox Code Playgroud)
然后当我运行Python REPL并导入tensorflow时,我得到:
$ python
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/phil/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 4, in <module>
from tensorflow.python import *
File "/home/phil/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 13, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/home/phil/.local/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 16, in <module>
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用该函数可视化tensorflow中卷积层的输出tf.image_summary
.我已经在其他情况下成功使用它(例如可视化输入图像),但是在这里正确地重塑输出有一些困难.我有以下转换层:
img_size = 256
x_image = tf.reshape(x, [-1,img_size, img_size,1], "sketch_image")
W_conv1 = weight_variable([5, 5, 1, 32])
b_conv1 = bias_variable([32])
h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)
Run Code Online (Sandbox Code Playgroud)
所以输出h_conv1
会有形状[-1, img_size, img_size, 32]
.只是使用tf.image_summary("first_conv", tf.reshape(h_conv1, [-1, img_size, img_size, 1]))
不考虑32个不同的内核,所以我基本上在这里切换不同的功能图.
我怎样才能正确地重塑它们?或者是否有另一个帮助函数可用于在摘要中包含此输出?
该MNIST For ML Beginners
教程是给我一个错误,当我运行print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
.其他一切都很好.
错误和跟踪:
InternalErrorTraceback (most recent call last)
<ipython-input-16-219711f7d235> in <module>()
----> 1 print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in run(self, fetches, feed_dict, options, run_metadata)
338 try:
339 result = self._run(None, fetches, feed_dict, options_ptr,
--> 340 run_metadata_ptr)
341 if run_metadata:
342 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.pyc in _run(self, handle, fetches, feed_dict, options, run_metadata)
562 try:
563 results = self._do_run(handle, target_list, unique_fetches,
--> 564 feed_dict_string, options, run_metadata)
565 finally:
566 # The …
Run Code Online (Sandbox Code Playgroud) 我已经设法使用命令行sklearn将图像加载到一个文件夹中: load_sample_images()
我现在想将其转换为numpy.ndarray
具有float32
数据类型的格式
我能够将它转换为np.ndarray
使用:np.array(X)
,np.array(X, dtype=np.float32)
然后np.asarray(X).astype('float32')
给我错误:
Run Code Online (Sandbox Code Playgroud)ValueError: setting an array element with a sequence.
有办法解决这个问题吗?
from sklearn_theano.datasets import load_sample_images
import numpy as np
kinect_images = load_sample_images()
X = kinect_images.images
X_new = np.array(X) # works
X_new = np.array(X[1], dtype=np.float32) # works
X_new = np.array(X, dtype=np.float32) # does not work
Run Code Online (Sandbox Code Playgroud) 假设我有一个非常简单的神经网络,如多层感知器.对于每一层,激活功能是S形的,并且网络是完全连接的.
在TensorFlow中,这可能是这样定义的:
sess = tf.InteractiveSession()
# Training Tensor
x = tf.placeholder(tf.float32, shape = [None, n_fft])
# Label Tensor
y_ = tf.placeholder(tf.float32, shape = [None, n_fft])
# Declaring variable buffer for weights W and bias b
# Layer structure [n_fft, n_fft, n_fft, n_fft]
# Input -> Layer 1
struct_w = [n_fft, n_fft]
struct_b = [n_fft]
W1 = weight_variable(struct_w, 'W1')
b1 = bias_variable(struct_b, 'b1')
h1 = tf.nn.sigmoid(tf.matmul(x, W1) + b1)
# Layer1 -> Layer 2
W2 = weight_variable(struct_w, 'W2')
b2 = bias_variable(struct_b, …
Run Code Online (Sandbox Code Playgroud) 我在sklearn中使用MinMaxScaler模型来规范化模型的功能.
training_set = np.random.rand(4,4)*10
training_set
[[ 6.01144787, 0.59753007, 2.0014852 , 3.45433657],
[ 6.03041646, 5.15589559, 6.64992437, 2.63440202],
[ 2.27733136, 9.29927394, 0.03718093, 7.7679183 ],
[ 9.86934288, 7.59003904, 6.02363739, 2.78294206]]
scaler = MinMaxScaler()
scaler.fit(training_set)
scaler.transform(training_set)
[[ 0.49184811, 0. , 0.29704831, 0.15972182],
[ 0.4943466 , 0.52384506, 1. , 0. ],
[ 0. , 1. , 0. , 1. ],
[ 1. , 0.80357559, 0.9052909 , 0.02893534]]
Run Code Online (Sandbox Code Playgroud)
现在我想使用相同的缩放器来规范化测试集:
[[ 8.31263467, 7.99782295, 0.02031658, 9.43249727],
[ 1.03761228, 9.53173021, 5.99539478, 4.81456067],
[ 0.19715961, 5.97702519, 0.53347403, 5.58747666],
[ 9.67505429, …
Run Code Online (Sandbox Code Playgroud)
我有一个非常简单的输入管道,from_generator
非常适合......
dataset = tf.data.Dataset.from_generator(complex_img_label_generator,
(tf.int32, tf.string))
dataset = dataset.batch(64)
iter = dataset.make_one_shot_iterator()
imgs, labels = iter.get_next()
Run Code Online (Sandbox Code Playgroud)
其中complex_img_label_generator
动态生成图像,并返回表示一个numpy的阵列(H, W, 3)
图像和一个简单的string
标签.处理不是我可以表示从文件和tf.image
操作中读取的内容.
我的问题是关于如何平衡发电机?我如何让N个这些生成器在自己的线程中运行.
一个想法是使用dataset.map
与num_parallel_calls
处理线程; 但是地图在张量上运行......另一个想法是创建多个生成器,每个生成器都有自己的,prefetch
并以某种方式加入它们,但我看不出我如何加入N个生成器流?
我可以遵循任何规范的例子吗?
tensorflow ×5
python ×4
scikit-learn ×2
c ×1
casting ×1
find ×1
malloc ×1
matplotlib ×1
numpy ×1
seaborn ×1
ubuntu ×1