已经在同一个网站上阅读了一篇关于这个帖子但没有用的帖子,我感觉有点难过,但我确信我之前已经这样做了.
我有一本词典.我想从Dictionary中获取前200个值.
Dictionary<int,SomeObject> oldDict = new Dictionary<int,SomeObject>();
//oldDict gets populated somewhere else.
Dictionary<int,SomeObject> newDict = new Dictionary<int,SomeObject>();
newDict = oldDict.Take(200).ToDictionary();
Run Code Online (Sandbox Code Playgroud)
显然,take返回一个IENumerable,所以你必须运行ToDictionary()将它转换回相同类型的字典.但是,它只是不起作用,它想要一些随机的键选择器 - 或者什么?我甚至尝试过施展,但无济于事.有任何想法吗?
我理解有关常量的一个重要事项是你不必经历并更新代码,在那里使用该常量.多数民众赞成,但是我们说你没有明确地宣布它为常数.如果HAPPENS实际上没有被改变并且使其成为常数,那么存在什么好处(s)是否会节省处理和/或代码的大小等等?
基本上我有一个程序,编译器说一个特定的变量没有改变,因此可以声明为常量,我只是想知道添加常量限定符对它有什么好处,如果它没有区别那么制作这种变化没有增加任何价值,因此没有浪费时间(同样的情况发生在多个地方)回去并"修复"所有这些变量.
我发现它们是扩展现有类的一种非常自然的方式,特别是当您只需要将某些功能"点焊"到现有类时.
微软表示,"一般来说,我们建议您谨慎实施扩展方法,并且只在必要时才实施." 然而,扩展方法构成了Linq的基础; 事实上,Linq是创建扩展方法的原因.
是否存在使用扩展方法而不是继承或组合的特定设计标准?他们劝阻什么标准?
所以,我有三张桌子:
阶级辩护:
engine = create_engine('sqlite://test.db', echo=False)
SQLSession = sessionmaker(bind=engine)
Base = declarative_base()
class Channel(Base):
__tablename__ = 'channel'
id = Column(Integer, primary_key = True)
title = Column(String)
description = Column(String)
link = Column(String)
pubDate = Column(DateTime)
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key = True)
username = Column(String)
password = Column(String)
sessionId = Column(String)
class Subscription(Base):
__tablename__ = 'subscription'
userId = Column(Integer, ForeignKey('user.id'), primary_key=True)
channelId = Column(Integer, ForeignKey('channel.id'), primary_key=True)
Run Code Online (Sandbox Code Playgroud)
注意:我知道user.username应该是唯一的,需要修复它,我不确定为什么SQLalchemy使用双引号创建一些行名称.
我正在尝试找到一种方法来检索所有频道,以及指示一个特定用户(由user.sessionId与user.id一起识别)的订阅频道.
例如,假设我们有四个通道:channel1,channel2,channel3,channel4; 用户:user1; 谁在channel1和channel4上订阅.user1的查询将返回如下内容:
channel.id | channel.title | …Run Code Online (Sandbox Code Playgroud) 简单的机器学习问题.可能有很多方法可以解决这个问题:
有4个可能的事件无限流:
'event_1', 'event_2', 'event_4', 'event_4'
事件不是完全随机的.我们假设大多数事件都有一些复杂的模式,其余的事件只是随机的.我们提前不知道这些模式.
收到每个事件后,我想根据事件过去的顺序预测下一个事件的内容.所以我的问题是:我应该为这个预测器使用什么机器学习算法?
然后,预测器将被告知下一个事件实际上是什么:
Predictor=new_predictor()
prev_event=False
while True:
event=get_event()
if prev_event is not False:
Predictor.last_event_was(prev_event)
predicted_event=Predictor.predict_next_event(event)
Run Code Online (Sandbox Code Playgroud)
问题在于预测者应该维持多长时间的历史,因为维持无限的历史将是不可能的.我会把这个留给你回答.但实际上答案不可能是无足轻重的.
因此,我认为预测必须通过某种滚动的历史来完成.因此,添加新事件并使旧事件过期应该相当有效,并且不需要重建整个预测器模型.
具体的代码,而不是研究论文,将为您的回复增添巨大的价值.Python或C库很不错,但任何事情都可以.
更新:如果在每一轮中同时发生多个事件,该怎么办?这会改变解决方案吗?
python compression machine-learning neural-network evolutionary-algorithm
我有一个类型的变量size_t,我想用它打印printf().我使用什么格式说明符来便携地打印它?
在32位机器上,%u似乎是对的.我编译了g++ -g -W -Wall -Werror -ansi -pedantic,并没有警告.但是当我在64位机器中编译该代码时,它会产生警告.
size_t x = <something>;
printf( "size = %u\n", x );
warning: format '%u' expects type 'unsigned int',
but argument 2 has type 'long unsigned int'
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,警告会消失,如果我将其更改为%lu.
问题是,如何编写代码,以便在32位和64位机器上编译警告?
编辑:作为一种解决方法,我想一个答案可能是将变量"转换"为一个足够大的整数,比如说unsigned long,并使用打印%lu.这在两种情况下都有效.我在寻找是否还有其他想法.
我有一个字符串,我需要找出它是否是一个unix时间戳,我怎么能有效地做到这一点?
我通过谷歌找到了这个帖子,但我不敢提出一个非常可靠的答案.(是的,我在上述帖子的原始海报中提出了问题).
我们的一个视图有一个ScrollView根布局.当设备旋转并被onConfigurationChanged()调用时,我们希望能够获得ScrollView新的宽度/高度.我们的代码如下所示:
@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.d(TAG, "Width: '" + findViewById(R.id.scrollview).getWidth() + "'");
Log.d(TAG, "Height: '" + findViewById(R.id.scrollview).getHeight() + "'");
super.onConfigurationChanged(newConfig);
Log.d(TAG, "Width: '" + findViewById(R.id.scrollview).getWidth() + "'");
Log.d(TAG, "Height: '" + findViewById(R.id.scrollview).getHeight() + "'");
}
Run Code Online (Sandbox Code Playgroud)
我们的AndroidManifest.xml的相关部分如下所示:
<activity android:name=".SomeActivity"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
最后,我们布局的相关部分如下所示:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollview"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
>
<LinearLayout android:id="@+id/container"
android:orientation="vertical"
android:layout_height="fill_parent"
android:minHeight="200dip"
android:layout_width="fill_parent"
>
Run Code Online (Sandbox Code Playgroud)
在我们的Droid上,我们期望ScrollView的宽度在切换到横向时变为854,在切换回纵向时变为480(并且高度与等效开关相同,减去菜单栏).但是,我们正好相反.这是我们的LogCat:
// Switching to landscape:
03-26 11:26:16.490: DEBUG/ourtag(17245): Width: '480' // Before super …Run Code Online (Sandbox Code Playgroud) 你知道一个用于DOM事件模拟的JS库吗?我知道这个操作可以完成,但我找不到任何库来做.
更新:我试着更好地解释我的问题.Javascript可以模拟用户点击等事件,我正在寻找一个帮助我完成此操作的库.
如何将UTF-8编码的字符串写入vba的文本文件中,如
Dim fnum As Integer
fnum = FreeFile
Open "myfile.txt" For Output As fnum
Print #fnum, "special characters: äöüß" 'latin-1 or something by default
Close fnum
Run Code Online (Sandbox Code Playgroud)
应用程序级别是否有一些设置?
c# ×2
python ×2
android ×1
c ×1
compression ×1
constants ×1
datetime ×1
dictionary ×1
dom ×1
events ×1
ienumerable ×1
javascript ×1
orientation ×1
php ×1
printf ×1
scrollview ×1
simulation ×1
sql ×1
sqlalchemy ×1
sqlite ×1
take ×1
time ×1
todictionary ×1
utf-8 ×1
vba ×1