如果输入为零,我想创建一个如下所示的数组:
[1,0,0,0,0,0,0,0,0,0]
Run Code Online (Sandbox Code Playgroud)
如果输入为5:
[0,0,0,0,0,1,0,0,0,0]
Run Code Online (Sandbox Code Playgroud)
对于上面我写道:
np.put(np.zeros(10),5,1)
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
有什么方法可以在一行中实现吗?
我从源(文档)安装tensorflow .
Cuda驱动版:
nvcc: NVIDIA (R) Cuda compiler driver
Cuda compilation tools, release 7.5, V7.5.17
Run Code Online (Sandbox Code Playgroud)
当我运行以下命令时:
bazel-bin/tensorflow/cc/tutorials_example_trainer --use_gpu
Run Code Online (Sandbox Code Playgroud)
它给了我以下错误:
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locally
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:925] successful NUMA node read from SysFS had negative value (-1), but there must be at least one …
Run Code Online (Sandbox Code Playgroud) 这是我正在运行的示例MNIST代码:
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32, shape=[None, 784])
y_ = tf.placeholder(tf.float32, shape=[None, 10])
W = tf.Variable(tf.zeros([784,10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x,W) + b)
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
def bias_variable(shape):
initial = tf.constant(0.1, shape=shape)
return tf.Variable(initial)
def conv2d(x, W):
return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')
def max_pool_2x2(x):
return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],
strides=[1, 2, 2, 1], padding='SAME')
W_conv1 = weight_variable([5, …
Run Code Online (Sandbox Code Playgroud) 我试图弄清楚为什么这不起作用(游乐场):
fn main() {
let a = vec![1, 2, 3, 4];
let b = a.clone();
// slice and iter (wrong way)
let s: i32 = &a[1..a.len()].iter()
.zip(&b[1..b.len()].iter())
.map(|(x, y)| x * y)
.sum();
println!("{}", s);
}
Run Code Online (Sandbox Code Playgroud)
错误:
rustc 1.13.0 (2c6933acc 2016-11-07)
error[E0277]: the trait bound `&std::slice::Iter<'_, {integer}>: std::iter::Iterator` is not satisfied
--> <anon>:6:10
|
6 | .zip(&b[1..b.len()].iter())
| ^^^ trait `&std::slice::Iter<'_, {integer}>: std::iter::Iterator` not satisfied
|
= note: `&std::slice::Iter<'_, {integer}>` is not an iterator; maybe try calling `.iter()` …
Run Code Online (Sandbox Code Playgroud) 我正在尝试按列获取唯一计数,但我的数组具有分类变量(dtype 对象)
val, count = np.unique(x, axis=1, return_counts=True)
Run Code Online (Sandbox Code Playgroud)
虽然我收到这样的错误:
TypeError: The axis argument to unique is not supported for dtype object
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
样品 x:
array([[' Private', ' HS-grad', ' Divorced'],
[' Private', ' 11th', ' Married-civ-spouse'],
[' Private', ' Bachelors', ' Married-civ-spouse'],
[' Private', ' Masters', ' Married-civ-spouse'],
[' Private', ' 9th', ' Married-spouse-absent'],
[' Self-emp-not-inc', ' HS-grad', ' Married-civ-spouse'],
[' Private', ' Masters', ' Never-married'],
[' Private', ' Bachelors', ' Married-civ-spouse'],
[' Private', ' Some-college', ' Married-civ-spouse']], dtype=object)
Run Code Online (Sandbox Code Playgroud)
需要以下计数: …
我试图在张量流上写一个分布式变分自动编码器standalone mode
.
我的群集包括3台机器,命名为m1,m2和m3.我试图在m1上运行1 ps服务器,在m2和m3上运行2个工作服务器.(分布式tensorflow文档中的示例培训师程序)在m3上,我收到以下错误消息:
Traceback (most recent call last):
File "/home/yama/mfs/ZhuSuan/examples/vae.py", line 241, in <module>
save_model_secs=600)
File "/mfs/yama/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/training/supervisor.py", line 334, in __init__
self._verify_setup()
File "/mfs/yama/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/training/supervisor.py", line 863, in _verify_setup
"their device set: %s" % op)
ValueError: When using replicas, all Variables must have their device set: name: "Variable"
op: "Variable"
attr {
key: "container"
value {
s: ""
}
}
attr {
key: "dtype"
value {
type: DT_INT32
}
}
attr {
key: "shape"
value { …
Run Code Online (Sandbox Code Playgroud) 说我有以下三个列表:
aList = [1,2,3,4,5,6]
bList = ['a','b','c','d']
cList = [1,2]
Run Code Online (Sandbox Code Playgroud)
我想使用来遍历它们zip
。
通过如下方式使用循环zip
:
from itertools import cycle
for a,b,c in zip(aList, cycle(bList), cycle(cList)):
print a,b,c
Run Code Online (Sandbox Code Playgroud)
我得到的结果是:
1 a 1
2 b 2
3 c 1
4 d 2
5 a 1
6 b 2
Run Code Online (Sandbox Code Playgroud)
虽然我希望我的结果像:
1 a 1
2 b 1
3 c 1
4 d 1
5 a 2
6 b 2
Run Code Online (Sandbox Code Playgroud) 我正在尝试切片矢量并在Rust中同时打印它.这是我的代码:
fn main() {
let a = vec![1, 2, 3, 4];
println!("{:?}", a[1..2]);
}
Run Code Online (Sandbox Code Playgroud)
错误:
error[E0277]: the trait bound `[{integer}]: std::marker::Sized` is not satisfied
--> src/main.rs:6:5
|
6 | println!("{:?}", a[1..3]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `[{integer}]: std::marker::Sized` not satisfied
|
= note: `[{integer}]` does not have a constant size known at compile-time
= note: required by `std::fmt::ArgumentV1::new`
= note: this error originates in a macro outside of the current crate
Run Code Online (Sandbox Code Playgroud)
如何打印此切片矢量?
我正在绘制不同地图上设备的每小时更新。为了动画和分析更新,我通过清除 jupyter 中单元格的输出在每次迭代中显示一个新图。
map_ = [[] for i in range(max(dfByDeviceidHourly['hour'])+1)]
for hour in dfByDeviceidHourly['hour'].unique():
df_map = dfByDeviceidHourly[dfByDeviceidHourly['hour'] == hour]
map_[hour] = folium.Map(location=list(df_map[['geocoordinates_latitude','geocoordinates_longitude']].mean()), zoom_start=13)
for i,mark in enumerate(df_map):
folium.Marker(list(df_map[['geocoordinates_latitude','geocoordinates_longitude']].iloc[i]), popup='The Waterfront').add_to( map_[hour] )
clear_output(wait = True)
display(map_[hour])
time.sleep(4)
Run Code Online (Sandbox Code Playgroud)
有什么方法可以让我从上面制作视频或 gif 吗?
我找到了一种方法(这里:https : //github.com/python-visualization/folium/issues/35),它涉及将图像保存为 html,将它们转换为 png,从中创建一个 gif,然后在笔记本。尽管我正在为它寻找更强大的替代方案。
我想在我的中心对齐输出(包括文本和图表)ipython notebook
.有没有一种方法可以在同一个笔记本中添加样式?代码或屏幕截图示例将有很大帮助.
我正在使用手电筒摘要
from torchsummary import summary
Run Code Online (Sandbox Code Playgroud)
我想在打印模型摘要时传递多个参数,但是这里提到的示例:pytorch中的模型摘要仅采用了一个参数。例如:
model = Network().to(device)
summary(model,(1,28,28))
Run Code Online (Sandbox Code Playgroud)
原因是 forward 函数需要两个参数作为输入,例如:
def forward(self, img1, img2):
Run Code Online (Sandbox Code Playgroud)
我如何在这里传递两个参数?
我想删除剧情边界内的额外空间
plt.boxplot(parkingData_agg['occupancy'], 0, 'rs', 0, 0.75)
plt.tight_layout() # This didn't work. Maybe it's not for the purpose I am thinking it is used for.
plt.yticks([0],['Average Occupancy per slot'])
fig = plt.figure(figsize=(5, 1), dpi=5) #Tried to change the figsize but it didn't work
plt.show()
Run Code Online (Sandbox Code Playgroud)
python ×10
tensorflow ×3
gpu ×2
numpy ×2
rust ×2
animated-gif ×1
bazel ×1
boxplot ×1
css ×1
cycle ×1
folium ×1
frequency ×1
ipython ×1
leaflet ×1
matplotlib ×1
mnist ×1
python-3.x ×1
pytorch ×1
unique ×1
zip ×1