我使用Python和NumPy并且在"转置"方面存在一些问题:
import numpy as np
a = np.array([5,4])
print(a)
print(a.T)
Run Code Online (Sandbox Code Playgroud)
调用a.T不是转置数组.如果a是例如[[],[]]然后它正确转置,但我需要转置[...,...,...].
我确信有一种明显的方法可以做到这一点,但现在不能想到任何光滑的东西.
基本上,反而提高了例外,我想获得True或False以查看是否在大熊猫存在价值df指数.
import pandas as pd
df = pd.DataFrame({'test':[1,2,3,4]}, index=['a','b','c','d'])
df.loc['g'] # (should give False)
Run Code Online (Sandbox Code Playgroud)
我现在的工作如下
sum(df.index == 'g')
Run Code Online (Sandbox Code Playgroud) numpy中是否有一个智能且节省空间的对称矩阵,它在写入[j][i]时自动(并透明地)填充位置[i][j]?
import numpy
a = numpy.symmetric((3, 3))
a[0][1] = 1
a[1][0] == a[0][1]
# True
print(a)
# [[0 1 0], [1 0 0], [0 0 0]]
assert numpy.all(a == a.T) # for any symmetric matrix
Run Code Online (Sandbox Code Playgroud)
一个自动的Hermitian也会很好,虽然在写作的时候我不需要它.
鞠躬我的Visual Studios请求,我使用Entity Framework Core(1.0.1)启动了我的最新项目
所以编写我的数据库模型,因为我总是使用'虚拟'说明符来启用List的延迟加载.虽然在加载父表时,似乎子目录永远不会加载.
父模型
public class Events
{
[Key]
public int EventID { get; set; }
public string EventName { get; set; }
public virtual List<EventInclusions> EventInclusions { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
儿童模特
public class EventInclusions
{
[Key]
public int EventIncSubID { get; set; }
public string InclusionName { get; set; }
public string InclusionDesc { get; set; }
public Boolean InclusionActive { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
向这些表添加新记录似乎可以正常工作,因为我习惯于将EventInclusions记录嵌套在Events记录中作为List.
虽然当我查询这个表
_context.Events.Where(e => e.EventName == "Test")
Run Code Online (Sandbox Code Playgroud)
问题
无论幕后数据如何,EventInclusions都将返回空值.
读了一下后,我感觉这是我通常使用的EF6和EF Core之间的变化 …
使用python从文本文件中读取行时,通常需要在处理文本之前截断行尾字符,如下例所示:
f = open("myFile.txt", "r")
for line in f:
line = line[:-1]
# do something with line
Run Code Online (Sandbox Code Playgroud)
是否有一种优雅的方式或习惯用于检索没有终结字符的文本行?
我试图将csv文件中的数据读入pandas数据帧,并访问第一列'Date'
import pandas as pd
df_ticks=pd.read_csv('values.csv', delimiter=',')
print(df_ticks.columns)
df_ticks['Date']
Run Code Online (Sandbox Code Playgroud)
产生以下结果
Index([u'Date', u'Open', u'High', u'Low', u'Close', u'Volume'], dtype='object')
KeyError: u'no item named Date'
Run Code Online (Sandbox Code Playgroud)
如果我尝试访问任何其他列,如"打开"或"音量",它按预期工作
我正在编写一个程序来自动编写一些C代码,(我正在编写将字符串解析为具有相同名称的枚举)C对字符串的处理并不是那么好.所以有些人一直在唠叨我试试python.
我创建了一个应该删除C风格/* COMMENT */和//COMMENT
字符串的函数:这是代码:
def removeComments(string):
re.sub(re.compile("/\*.*?\*/",re.DOTALL ) ,"" ,string) # remove all occurance streamed comments (/*COMMENT */) from string
re.sub(re.compile("//.*?\n" ) ,"" ,string) # remove all occurance singleline comments (//COMMENT\n ) from string
Run Code Online (Sandbox Code Playgroud)
所以我尝试了这个代码.
str="/* spam * spam */ eggs"
removeComments(str)
print str
Run Code Online (Sandbox Code Playgroud)
它显然没有做任何事情.
关于我做错了什么的任何建议?
有一种说法,我听过几次:
如果您遇到问题而尝试使用Regex解决问题,最终会遇到两个问题.
编辑:回顾这几年后.(经过更多的解析经验)
我认为正则表达式可能是正确的解决方案.而这里使用的简单正则表达"足够好".我可能没有在这个问题上强调这一点.这是针对单个特定文件的.那没有棘手的情况.我认为保持文件解析对于正则表达式而言要简单得多,而不是将正则表达式复杂化为不可读的符号汤.
我想把传说放在下面的每个子图中.我试过用plt.legend但它没有用.
有什么建议?
提前致谢 :-)
f, (ax1, ax2, ax3) = plt.subplots(3, sharex=True, sharey=True)
ax1.plot(xtr, color='r', label='Blue stars')
ax2.plot(ytr, color='g')
ax3.plot(ztr, color='b')
ax1.set_title('2012/09/15')
plt.legend([ax1, ax2, ax3],["HHZ 1", "HHN", "HHE"])
plt.show()
Run Code Online (Sandbox Code Playgroud)
根据atomh33ls的建议:
ax1.legend("HHZ 1",loc="upper right")
ax2.legend("HHN",loc="upper right")
ax3.legend("HHE",loc="upper right")
Run Code Online (Sandbox Code Playgroud)
图例位置是固定的,但是字符串似乎有问题,因为每个字母都放在一个新行中.
有谁知道如何解决它?

我的问题很常见,但我一直在寻找和尝试我找到的所有解决方案,但仍然无效.所以任何帮助将不胜感激!=)
提前致谢!
我在编译时遇到此错误:
g++ -ISFML/include -Iclasses/ -W -Wall -Werror -c -o classes/Object.o classes/Object.cpp
In file included from classes/Core.hh:18:0,
from classes/Object.hh:4,
from classes/Object.cpp:1:
classes/MapLink.hh:9:1: error: invalid use of incomplete type ‘struct Object’
classes/MapLink.hh:6:7: error: forward declaration of ‘struct Object’
In file included from classes/Core.hh:19:0,
from classes/Object.hh:4,
from classes/Object.cpp:1:
classes/Player.hh:9:1: error: invalid use of incomplete type ‘struct Object’
classes/MapLink.hh:6:7: error: forward declaration of ‘struct Object’
make: *** [classes/Object.o] Error 1
Run Code Online (Sandbox Code Playgroud)
所以基本上,我有一个主要包含(main.cpp)
#include "Core.hh"
int main(void)
{
...
}
Run Code Online (Sandbox Code Playgroud)
这是包含我所有包含的头文件(Core.hh)
#ifndef __CORE_HH__
# …Run Code Online (Sandbox Code Playgroud) 我正在处理文件数量,文件的每个处理将输出几千个浮点数组,我将所有文件的数据存储在一个大型数据集中的单个hdf5中,以便进一步处理.
目前我很困惑如何将我的数据附加到hdf5文件中.(在上面的代码中注释)在上面的2个for循环中,正如你所看到的,我想一次将1维float数组追加到hdf5中,而不是整个东西.我的数据是以TB为单位,我们只能将数据附加到文件中.
有几个问题:
或者这不可能吗?
编辑:
我一直在关注Simon的建议,目前这里是我的更新代码:
hid_t desFi5;
hid_t fid1;
hid_t propList;
hsize_t fdim[2];
desFi5 = H5Fcreate(saveFilePath, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
fdim[0] = 3;
fdim[1] = 1;//H5S_UNLIMITED;
fid1 = H5Screate_simple(2, fdim, NULL);
cout << "----------------------------------Space done\n";
propList = H5Pcreate( H5P_DATASET_CREATE);
H5Pset_layout( propList, H5D_CHUNKED );
int ndims = 2;
hsize_t chunk_dims[2];
chunk_dims[0] = 3;
chunk_dims[1] = 1;
H5Pset_chunk( propList, ndims, chunk_dims );
cout << "----------------------------------Property done\n";
hid_t dataset1 = H5Dcreate( desFi5, "des", H5T_NATIVE_FLOAT, fid1, …Run Code Online (Sandbox Code Playgroud)