我开始使用本教程为初学者学习MatPlotLib .这是第一个例子.
from pylab import *
X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
C,S = np.cos(X), np.sin(X)
Run Code Online (Sandbox Code Playgroud)
如果我将这3行写入我的python文件并在命令行中执行(通过键入python file_name.py
),则没有任何反应.没有错误信息,没有情节.
有谁知道为什么我没看到情节?
添加
当然我需要使用show
.但即使我添加以下3行:
plot(X,C)
plot(X,S)
show()
Run Code Online (Sandbox Code Playgroud)
它仍然没有产生任何东西.
添加
以下是我现在使用的行:
import pylab as p
C = [1,2,3,4]
S = [10, 20, 30, 10]
p.plot(C,S)
p.show()
Run Code Online (Sandbox Code Playgroud)
我仍然有相同的结果(没有).
我有一个目录,其中保存所有源文件和头文件.我想运行Doxygen来生成这些源代码的文档.但是,我不想更改此目录中的任何内容(特别是我无法添加将保存Doxygen文档的子目录).
我怎样才能达到我的需要?
我想我需要做以下事情: - 我创建并转到'documentation'目录.- 在此目录中,我执行doxygen -g
以创建名为"Doxyfile"的模板配置文件. - 然后,我想,我需要修改Doxyfile以指示源代码不在当前目录中.
那么,输出会自动(默认情况下)保存在执行Doxygen的目录中吗?
我有一个pandas数据框并将其分为两列(例如col1
和col2
).为固定值col1
和col2
(即,对于A组)我可以在几个不同的值col3
.我想计算第三列中不同值的数量.
例如,如果我将此作为输入:
1 1 1
1 1 1
1 1 2
1 2 3
1 2 3
1 2 3
2 1 1
2 1 2
2 1 3
2 2 3
2 2 3
2 2 3
Run Code Online (Sandbox Code Playgroud)
我想将此表(数据框)作为输出:
1 1 2
1 2 1
2 1 3
2 2 1
Run Code Online (Sandbox Code Playgroud) 我尝试通过执行以下命令为Python 3安装pandas:
sudo pip3 install pandas
Run Code Online (Sandbox Code Playgroud)
结果我得到了这个:
Downloading/unpacking pandas
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement pandas
Cleaning up...
No distributions at all found for pandas
Run Code Online (Sandbox Code Playgroud)
也许有趣的是,Python 2的安装工作正常.
sudo pip install pandas
Run Code Online (Sandbox Code Playgroud)
返回以下内容:
Requirement already satisfied (use --upgrade to upgrade): pandas in /usr/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /usr/lib/python2.7/dist-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): pytz>=2011k in /usr/lib/python2.7/dist-packages (from pandas)
Requirement already satisfied (use --upgrade …
Run Code Online (Sandbox Code Playgroud) 我有以下代码:
game.log.fine("HERE" + bestMove.get("score"));
Integer bestScore = Integer.getInteger(bestMove.get("score"));
game.log.fine("THERE" + bestScore);
Run Code Online (Sandbox Code Playgroud)
作为输出我有:
FINE: HERE50
Dec 9, 2010 11:34:17 AM game.Agent getCloud
FINE: THEREnull
Dec 9, 2010 11:34:17 AM game.Agent getCloud
Run Code Online (Sandbox Code Playgroud)
可能我不得不补充一点,bestMove是HashMap<String,String>
.
问题是bestMove.get("score")
给出一个字符串值(等于"50").但如果尝试转换为整数,我得到null
.
有人知道这里有什么问题吗?
在"工作目录"中,我有很多*.cpp和*.h文件,#include
彼此和子目录中的文件.
例如:
#include "first.h"
#include "second.h"
#include "dir1/third.h"
#include "dir2/fourth.h"
Run Code Online (Sandbox Code Playgroud)
在我自己的目录中(与"工作"目录不同)我想创建一个新的*.cpp和*.h文件,其中包含"working"目录中的一个文件.例如:
#include "/root/workingdirectory/first.h"
Run Code Online (Sandbox Code Playgroud)
但是,它不起作用.因为"first.h"可能包含"second.h",而"second.h"不在我的目录中.有没有办法告诉编译器它需要搜索不在当前但在工作目录中的包含文件:/root/workingdirectory/
?
使它更复杂,dir1
并且dir2
不在我的工作目录中.它们位于/root/workingdirectory2/
.所以,我的第二个问题是,是否有可能通过让编译器知道子目录位于其他地方来解决这个问题?
我还需要补充一点,我不使用任何环境进行开发并从命令行编译(使用g++
).
我的工作的最终结果应该是一个Python函数,它将JSON对象作为唯一的输入并返回另一个JSON对象作为输出.为了使它更具体,我是一名数据科学家,我所说的功能来自数据,它提供了预测(换句话说,它是一个机器学习模型).
所以,我的问题是如何将这个功能提供给将要将其整合到Web服务中的"技术团队".
目前我面临的问题很少.首先,技术团队不一定在Python环境中工作.因此,他们不能只将我的功能"复制并粘贴"到他们的代码中.其次,我想确保我的功能在与我相同的环境中运行.例如,我可以想象我使用了一些技术团队没有的库,或者他们的版本与我使用的版本不同.
添加
作为可能的解决方案,我考虑以下内容.我启动一个Python进程,它监听套接字,接受传入的字符串,将它们转换为JSON,将JSON提供给"已发布"函数,并将输出JSON作为字符串返回.这个解决方案有缺点吗?换句话说,将一个Python函数"发布"为一个监听套接字的后台进程是一个好主意吗?
我尝试重现TensorFlow的LSTMCell生成的结果,以确保我知道它的作用.
这是我的TensorFlow代码:
num_units = 3
lstm = tf.nn.rnn_cell.LSTMCell(num_units = num_units)
timesteps = 7
num_input = 4
X = tf.placeholder("float", [None, timesteps, num_input])
x = tf.unstack(X, timesteps, 1)
outputs, states = tf.contrib.rnn.static_rnn(lstm, x, dtype=tf.float32)
sess = tf.Session()
init = tf.global_variables_initializer()
sess.run(init)
x_val = np.random.normal(size = (1, 7, num_input))
res = sess.run(outputs, feed_dict = {X:x_val})
for e in res:
print e
Run Code Online (Sandbox Code Playgroud)
这是它的输出:
[[-0.13285545 -0.13569424 -0.23993783]]
[[-0.04818152 0.05927373 0.2558436 ]]
[[-0.13818116 -0.13837864 -0.15348436]]
[[-0.232219 0.08512601 0.05254192]]
[[-0.20371495 -0.14795329 -0.2261929 ]]
[[-0.10371902 -0.0263292 -0.0914975 …
Run Code Online (Sandbox Code Playgroud) 我刚刚发现我可以使用Python 编写一个非常简单的Web服务器.我已经有一个Apache Web服务器,我想在这台机器上尝试基于Python的Web服务器.但是如果我尝试的话,我担心会遇到某种冲突.我的意思是两个Web服务器将如何"决定"谁需要服务来自客户端的请求?
为什么主要方法必须放入一个类?我理解OOP的主要思想,但我不明白为什么主程序是在一个类中定义的.这样的类会在某处实例化吗?我的意思是课外没有代码.定义类并且从不使用此类的对象的原因是什么?
python ×6
c++ ×2
java ×2
pandas ×2
apache ×1
class ×1
conflict ×1
deployment ×1
doxygen ×1
filesystems ×1
group-by ×1
include ×1
input ×1
install ×1
integer ×1
lstm ×1
matplotlib ×1
pip ×1
publish ×1
python-3.4 ×1
sockets ×1
string ×1
tensorflow ×1
webserver ×1