你能帮我在R做一个类似的情节吗?
我希望它具有交互性,以便我可以旋转球体.我想我应该用rgl.我发现一个例子相似,我需要在这里,但是我无法找到一个方法来绘制一个网格,而不是一个充满球体.
UPD:可以帮助回答问题的可重现数据集(我从这里开始):
u <- runif(1000,0,1)
v <- runif(1000,0,1)
theta <- 2 * pi * u
phi <- acos(2 * v - 1)
x <- sin(theta) * cos(phi)
y <- sin(theta) * sin(phi)
z <- cos(theta)
library("lattice")
cloud(z ~ x + y)
Run Code Online (Sandbox Code Playgroud) 我使用pathlib递归匹配所有文件以根据文件内容过滤文件。然后我想找到这个文件的文件夹的顶层是什么。假设如下。我在文件夹中有一个文件:
a/b/c/file.log
我从级别进行搜索a:
for f in path_data.glob("**/*"):
if something inside file f:
# I would like to get in what folder this file is, i.e. 'b'
Run Code Online (Sandbox Code Playgroud)
我现在可以使用以下方法获得所有父母级别:
f.parents 会给我 b/cf.parent 会给我 cf.name 会给我 file.log但我怎么能得到b呢?
准确地说:存储文件的级别数未知。
UPD:我知道我可以用 split 来做到这一点,但我想知道是否有合适的 API 来做到这一点。我找不到。
我需要在 Python 中可视化几个重叠的标量字段。我找到了mayavi图书馆来做这种情节。问题是我不明白如何为标量字段自定义颜色映射。我的想法是为每个字段设置一种颜色的阴影。我试图采用一个例子,但它不起作用。这是我使用红色阴影可视化标量场的代码:
import numpy as np
from mayavi import mlab
x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
s = np.sin(x*y*z)/(x*y*z)
src = mlab.pipeline.scalar_field(s)
volume = mlab.pipeline.volume(src)
lut = np.zeros((256, 4), np.uint8)
lut[:,-1] = 255
lut[:, 0] = np.linspace(0, 255, 256)
volume.module_manager.scalar_lut_manager.lut.table = lut
mlab.draw()
mlab.view(40, 85)
mlab.show()
Run Code Online (Sandbox Code Playgroud)
但是,输出图始终带有标准的蓝红查找表。
我想更改两个轴的书脊宽度:
img = np.random.normal(size=(100, 100))
fig, ax = plt.subplots()
cax = ax.imshow(img)
cbar = fig.colorbar(cax, ticks=np.linspace(0, 70, 8))
[i.set_linewidth(3) for i in cbar.ax.spines.itervalues()]
[i.set_linewidth(3) for i in ax.spines.itervalues()]
Run Code Online (Sandbox Code Playgroud)
然而,结果我得到以下结果:
如何更改着色器轴的脊柱长度?
我注意到使用和不使用上下文管理器定义会话时会有所不同.这里有一个例子:
上下文管理器:
import tensorflow as tf
graph = tf.Graph()
with graph.as_default():
x = tf.Variable(0)
tf.summary.scalar("x", x)
with tf.Session(graph=graph) as sess:
summaries = tf.summary.merge_all()
print("Operations:", sess.graph.get_operations())
print("\nSummaries:", summaries)
Run Code Online (Sandbox Code Playgroud)
结果是:
Operations: [<tf.Operation 'Variable/initial_value' type=Const>, <tf.Operation 'Variable' type=VariableV2>, <tf.Operation 'Variable/Assign' type=Assign>, <tf.Operation 'Variable/read' type=Identity>, <tf.Operation 'x/tags' type=Const>, <tf.Operation 'x' type=ScalarSummary>, <tf.Operation 'Merge/MergeSummary' type=MergeSummary>]
Summaries: Tensor("Merge/MergeSummary:0", shape=(), dtype=string)
Run Code Online (Sandbox Code Playgroud)
没有上下文管理器
import tensorflow as tf
graph = tf.Graph()
with graph.as_default():
x = tf.Variable(0)
tf.summary.scalar("x", x)
sess = tf.Session(graph=graph)
summaries = tf.summary.merge_all()
print("Operations:", sess.graph.get_operations())
print("Summaries:", summaries)
sess.close() …Run Code Online (Sandbox Code Playgroud) 我看到了关于如何在Jupyter笔记本中可视化张量流图的这个问题.我发现这个答案来自这个例子,只有一个修改(tensor.tensor_content = bytes("<stripped %d bytes>"%size, 'utf-8')被替换tensor.tensor_content = "<stripped %d bytes>"%size).但是,如果我尝试tensorflow_inception_graph.pb在可视化上重新运行它不起作用:iframe是白色的,并且没有显示节点.
如果你向我解释我做错了什么,我将非常感激.这里有一个简单的例子来重现这个问题.
进口:
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
import tensorflow as tf
import numpy as np
from IPython.display import clear_output, Image, display, HTML
Run Code Online (Sandbox Code Playgroud)
创建图表:
graph = tf.Graph()
sess = tf.InteractiveSession(graph=graph)
x = tf.placeholder(tf.float32, shape=[None, 25, 25, 3], name='x')
y_true = tf.placeholder(tf.float32, shape=[None, 10], name='y_true')
y_true_cls = tf.argmax(y_true, dimension=1, name='y_true_cls')
print graph.get_operations()
Run Code Online (Sandbox Code Playgroud)
输出:
[<tensorflow.python.framework.ops.Operation at 0x115902850>,
<tensorflow.python.framework.ops.Operation at 0x115902690>,
<tensorflow.python.framework.ops.Operation at …Run Code Online (Sandbox Code Playgroud) 这里有一个例子:
df = pd.DataFrame(np.random.rand(100).reshape(20, 5))
df.head()
Run Code Online (Sandbox Code Playgroud)
它给:
0 1 2 3 4
0 0.424436 0.831037 0.685421 0.170769 0.179134
1 0.984879 0.837583 0.289348 0.403940 0.760511
2 0.216087 0.876270 0.849723 0.020144 0.573268
3 0.558212 0.083600 0.345405 0.492531 0.744830
4 0.708427 0.084600 0.743003 0.459426 0.354911
Run Code Online (Sandbox Code Playgroud)
我应用以下功能:
df.groupby([0, 1, 2]).apply(lambda x: pd.DataFrame({
"3sq": x[3].values**2,
"4sq": x[4].values**2,
"3*4": x[3].values*x[4].values,
})).reset_index().head()
Run Code Online (Sandbox Code Playgroud)
结果是:
0 1 2 level_3 3*4 3sq 4sq
0 0.009899 0.122257 0.159538 0 0.559871 0.501726 0.624755
1 0.105528 0.643789 0.219537 0 0.115762 0.199059 0.067321
2 …Run Code Online (Sandbox Code Playgroud) 我正在尝试编译以下最小示例GLFW:
#include <GLFW/glfw3.h>
#include <thread>
int main() {
glfwInit();
std::this_thread::sleep_for(std::chrono::seconds(1));
glfwTerminate();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的CMakeLists.txt文件是:
cmake_minimum_required(VERSION 3.9)
project(viewer)
set(CMAKE_CXX_STANDARD 11)
find_package(glfw3 3.2 REQUIRED)
include_directories(${GLFW_INCLUDE_DIRS})
add_executable(viewer main.cpp)
target_link_libraries(viewer ${GLFW_LIBRARIES})
Run Code Online (Sandbox Code Playgroud)
如果我尝试编译代码,它会失败并显示以下错误消息:
[ 50%] Linking CXX executable visualiser
Undefined symbols for architecture x86_64:
"_glfwInit", referenced from:
_main in main.cpp.o
"_glfwTerminate", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [visualiser] …Run Code Online (Sandbox Code Playgroud) 在以下环境中:
我正在尝试运行:
install.packages("rJava", type='source')
Run Code Online (Sandbox Code Playgroud)
但是,它失败并出现以下错误:
clang -o libjri.jnilib Rengine.o jri.o Rcallbacks.o Rinit.o globals.o rjava.o -dynamiclib -framework JavaVM -L/usr/local/opt/gettext/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -L/usr/local/opt/gettext/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -L/usr/local/Cellar/r/4.0.3/lib/R/lib -lR -L/usr/local/Cellar/pcre2/10.35/lib -lpcre2-8 -llzma -lbz2 -lz -licucore -ldl -lm -liconv
ld: framework not found JavaVM
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libjri.jnilib] Error 1
make[1]: *** [src/JRI.jar] Error 2
make: *** [jri] Error 2
ERROR: compilation failed for package ‘rJava’ …Run Code Online (Sandbox Code Playgroud) python ×4
r ×2
tensorflow ×2
3d ×1
c++ ×1
clion ×1
cmake ×1
dataframe ×1
ipython ×1
java ×1
jupyter ×1
macos ×1
matplotlib ×1
mayavi ×1
opengl ×1
pandas ×1
pathlib ×1
python-3.x ×1
rjava ×1
tensorboard ×1