我在Pandas有一个时间序列,日期是在月末:
import pandas as pd
s = pd.Series({
'2018-04-30': 0,
'2018-05-31': 1,
'2018-06-30': 0,
'2018-07-31': 1,
'2018-08-31': 0,
'2018-09-30': 1,
})
s.index = pd.to_datetime(s.index)
Run Code Online (Sandbox Code Playgroud)
当我用matplotlib绘制这个时,我会得到我期望的结果,月末的点数和2018年5月之前的行:
import matplotlib.pyplot as plt
plt.plot(s)
Run Code Online (Sandbox Code Playgroud)
但是熊猫本土的情节函数在月初绘制了积分:
s.plot()
Run Code Online (Sandbox Code Playgroud)
我想也许这只是熊猫将"4月30日"标记为"四月",但情况似乎并非如此:
s2 = pd.Series([0.2, 0.7], index=pd.date_range('2018-05-01', '2018-05-02'))
s.plot()
s2.plot()
Run Code Online (Sandbox Code Playgroud)
这是Pandas的一个错误还是我在这里做错了什么?
我几乎不知道我在这里做了什么,我以前从未做过这样的事情,但我和朋友正在编写竞争的国际象棋程序,他们需要能够相互沟通.
他将主要用C语言写作,我的大部分内容将使用Python,我可以看到一些选项:
人们推荐什么,我在哪里可以开始阅读?
c python networking network-protocols inter-process-communicat
我有一个简单的类,它的索引运算符我已经重载:
class dgrid{
double* data; // 1D Array holds 2D data in row-major format
public:
const int nx;
const int ny;
double* operator[] (const int index) {return &(data[index*nx]);}
}
Run Code Online (Sandbox Code Playgroud)
这种方式dgrid[x][y]
可用作2d数组,但数据在内存中是连续的.
但是,从内部成员函数来看,这有点笨重,我需要做一些有用的东西(*this)[x][y]
,但看起来很臭,特别是当我有以下部分时:
(*this)[i][j] = (*this)[i+1][j]
+ (*this)[i-1][j]
+ (*this)[i][j+1]
+ (*this)[i][j-1]
- 4*(*this)[i][j];
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?像this->[x][y]
(但这不起作用).使用一点功能f(x,y) returns &data[index*nx+ny]
是唯一的选择吗?
我的堆栈中有一个容器,每次我都需要重新创建docker-compose up
.我可以,docker-compose up --force-recreate
但这会重新创建我的所有容器.是否有语法(可能是docker-compose.yml文件)用于指定每种服务的这种标志?
我习惯性地编写具有大量功能的代码,我觉得它更清晰.但是现在我在Fortran中编写了一些需要非常高效的代码,我想知道过度使用函数是否会降低它的速度,或者编译器是否会解决正在发生的事情并进行优化?
我知道在Java/Python等中,每个函数都是一个对象,因此创建大量函数需要在内存中创建它们.我也知道在Haskell中,函数相互减少,所以它没什么区别.
有没有人知道Fortran的情况?使用intent/pure函数/声明更少的局部变量/其他任何东西是否有区别?
当我创建并绘制此列表时:
var = 2;
okList = {{0.8, var, 0.8, 0.8}, {0, 0.3, 0.6, 0.9}, {0, 1, 2, 3}};
lp = ListDensityPlot[okList, ColorFunction -> "SandyTerrain"]
Run Code Online (Sandbox Code Playgroud)
或者,未缩放,像这样:
lp = ListDensityPlot[okList, ColorFunction -> "SandyTerrain",
ColorFunctionScaling -> False]
Run Code Online (Sandbox Code Playgroud)
正如我所料,我得到了一个全彩色的正方形.
但是,当我尝试这个:
var = 0.8;
list = {{0.8, var, 0.8, 0.8}, {0, 0.3, 0.6, 0.9}, {0, 1, 2, 3}};
problem = ListDensityPlot[list, ColorFunction -> "SandyTerrain"]
Run Code Online (Sandbox Code Playgroud)
我在拐角处得到一个白色的补丁.
哪个用ColorFunctionScaling-> False绘图并没有摆脱
ColorFunction SandyTerrain中没有任何白色,因此必须是ListDensityPlot才能在该区域中绘制任何内容.
什么可能导致这种情况发生,我该如何阻止它?
有没有办法将字符放在vim中的特定行,即使该行很短?
例如,我正在为一个项目做出贡献,该项目具有79列宽的注释块样式,在任一端都有注释字符,例如
!--------------!
! Comment !
! More Comment !
!--------------!
Run Code Online (Sandbox Code Playgroud)
但即使猜测大数字(35i <SPACE> <ESC>),空间也很烦人
是否有一个简单的命令可以为我,或宏或我能写的东西?
我知道我可以使用 录制宏q<char>
并运行它们@<char>
。我还知道我可以使用@@
.
但是@@
是两个完整的按键!这也太多了吧!特别是当我多次运行该宏时。我知道,但如果我事先<num>@<char>
不知道怎么办?<num>
我实际上正在寻找类似运行宏的交互式搜索和替换(请参阅Vim 中的交互式搜索/替换正则表达式?)。这可以做到吗?
我正在尝试使用大数(~10 ^ 14),我需要能够存储它们并迭代那个长度的循环,即
n=SOME_BIG_NUMBER
do i=n,1,-1
Run Code Online (Sandbox Code Playgroud)
我尝试了通常的星形符号kind=8
等,但似乎没有任何效果.然后我检查了huge
内在函数和代码:
program inttest
print *,huge(1)
print *,huge(2)
print *,huge(4)
print *,huge(8)
print *,huge(16)
print *,huge(32)
end program inttest
Run Code Online (Sandbox Code Playgroud)
在所有情况下产生数字2147483647.为什么是这样?我在64位机器上使用gfortran(f95).
如果我需要一个bignum图书馆,人们会建议哪一个?
我需要通过删除输入文件的前两行来创建输出文本文件.
目前我正在使用sed"1,2d"input.txt> output.txt
我需要为成千上万的文件执行此操作,因此使用python:
import os
for filename in somelist:
os.system('sed "1,2d" %s-in.txt > %s-out.txt'%(filename,filename))
Run Code Online (Sandbox Code Playgroud)
但这很慢.
我需要保留原始文件,所以我无法进行到位.
有没有办法更快地做到这一点?使用除sed以外的东西?也许使用一些其他脚本语言而不是python?是否值得编写一个简短的C程序,或者文件写入磁盘访问是否可能成为瓶颈?
python ×3
fortran ×2
vim ×2
c ×1
c++ ×1
docker ×1
dockerfile ×1
file-io ×1
graph ×1
largenumber ×1
loops ×1
matplotlib ×1
networking ×1
optimization ×1
pandas ×1
performance ×1
plot ×1
sed ×1
vi ×1
vim-macros ×1