我刚刚完成RecyclerView了我的Android Application测试,但是在测试时,我发现了一个我不明白的奇怪的错误.当活动启动时,Recycler视图中的项目RecyclerView位于正确的距离.但是,一旦我开始滚动它们彼此分开,直到一次只能看到一个项目,并且你必须distance almost equivalent在看到下一个项目之前滚动到屏幕的那个项目.
这是bug的样子:
在滚动活动午餐之前
滚动循环视图后
如果您知道可能导致这种情况的原因,我们将非常感谢您的帮助.
以下是活动中的RecyclerView代码:
private ArrayList<String> imagesUrlListThumb, imagesUrlListFull = new ArrayList<String>();
private RecyclerAdapter recyclerAdapter;
private String urlRecyclerThumb = "";
private RecyclerView recyclerView;
private ImageView imgCurRecyclerView;
imagesUrlListThumb = produit.getImgUrlThumbMul();
recyclerAdapter = new RecyclerAdapter(getApplicationContext(), imagesUrlListThumb);
recyclerView = (RecyclerView) findViewById(R.id.content_product_detail_recycer_view);
RecyclerView.LayoutManager recyclerLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(recyclerLayoutManager);
recyclerView.setAdapter(recyclerAdapter);
urlRecyclerThumb = imagesUrlListThumb.get(0);
RecyclerItemClickSupport.addTo(recyclerView).setOnItemClickListener(new RecyclerItemClickSupport.OnItemClickListener() {
@Override
public void onItemClicked(RecyclerView rv, int pos, View view) {
urlRecyclerThumb = imagesUrlListThumb.get(pos); …Run Code Online (Sandbox Code Playgroud) 我正在使用Folium在Python中创建地图.
我有一个Pandas DataFrame,其中条目(纬度和经度)按时间索引.我想一次一小时地绘制这些条目(从00:00到01:00 ......从23:00到00:00),以便在地图上看到这些位置的演变.
有没有办法在Folium中为此目的创建动画或视频.
我有一个数据框df:
data = {'id':[12,112],
'idlist':[[1,5,7,12,112],[5,7,12,111,113]]
}
df=pd.DataFrame.from_dict(data)
Run Code Online (Sandbox Code Playgroud)
看起来像这样:
id idlist
0 12 [1, 5, 7, 12, 112]
1 112 [5, 7, 12, 111, 113]
Run Code Online (Sandbox Code Playgroud)
我需要检查是否id在中idlist,然后选择或标记它。我尝试了以下变化并收到注释的错误:
df=df.loc[df.id.isin(df.idlist),:] #TypeError: unhashable type: 'list'
df['flag']=df.where(df.idlist.isin(df.idlist),1,0) #TypeError: unhashable type: 'list'
Run Code Online (Sandbox Code Playgroud)
一些可能的其他解决方法将.apply在列表理解中?
我在这里寻找一个解决方案,要么选择其中的行id为idlist,或标志为1,其中排id在idlist。结果df应为:
id idlist
0 12 [1, 5, 7, 12, 112]
Run Code Online (Sandbox Code Playgroud)
要么:
flag id idlist
0 1 12 [1, 5, 7, 12, 112]
1 0 112 [5, …Run Code Online (Sandbox Code Playgroud) 我有以下问题。我有一个像这样的 numpy 数组:
arr = np.array([[ 1. , 1. , 4. , 3. , 6. , 12. , -1. , 1.],
[ 1. , 2. , 2., 2., 10. , 6. , -2. , 2.],
[ 1. , 2. , 3. , 4. , 4. , 11. , -2. , 3.],
[ 1. , 2. , 3. , 6., 8. , 9. , 1. , 4.],
[ 1. , 2. , 6. , 7. , 4., 14. , 1. , …Run Code Online (Sandbox Code Playgroud) 我有两个相同单位的变量,我想在与Bokeh相同的x轴上绘制.看起来像plot.multi_line是正确的工具,但我无法从doc找到正确的语法.我尝试了什么(从文档中收集):
# df is a pandas DataFrame with contains 3 columns x, y1, y2
source = ColumnDataSource(data=df)
plot=figure()
plot.multi_line(['x','x'], ['y1', 'y2'], source=source)
Run Code Online (Sandbox Code Playgroud)
或者试过:
plot.multi_line(xs=['x','x'], ys=['y1', 'y2'], source=source)
Run Code Online (Sandbox Code Playgroud)
结果是
RuntimeError:无法提供用户定义的数据源和可迭代值到字形方法.或者:
将所有数据直接作为文字传递:
p.circe(x = a_list,y = an_array,...)
或者,将所有数据放在ColumnDataSource中并传递列名:
source = ColumnDataSource(data = dict(x = a_list,y = an_array))p.circe(x ='x',y ='x',source = source,...)
Doc给出了这个例子:
p.multi_line([[1, 3, 2], [3, 4, 6, 6]], [[2, 1, 4], [4, 7, 8, 5]],
color=["firebrick", "navy"], alpha=[0.8, 0.3], line_width=4)
Run Code Online (Sandbox Code Playgroud)
我显然不想用原始列表传递值.我不明白,我需要一些帮助.
我的目标是使用一个颜色图,它通过一个字典,一个给定的数字映射到一个给定的颜色。
但是,matplotlib似乎已将数字标准化。
例如,我首先创建了一个自定义颜色图 use seaborn,并将其输入plt.scatter
import seaborn as sns
colors = ['pumpkin', "bright sky blue", 'light green', 'salmon', 'grey', 'pale grey']
pal = sns.xkcd_palette(colors)
sns.palplot(pal)
Run Code Online (Sandbox Code Playgroud)
from matplotlib import pyplot as plt
from matplotlib.colors import ListedColormap
cmap = ListedColormap(pal.as_hex())
x = [0, 1, 2]
y = [0, 1, 2]
plt.scatter(x, y, c=[0, 1, 2], s=500, cmap=cmap) # I'd like to get color ['pumpkin', "bright sky blue", 'light green']
Run Code Online (Sandbox Code Playgroud)
但是,它给了我颜色 ['pumpkin', 'salmon', 'pale grey']
简而言之: 颜色图 …
我有一个运行Windows“ net user”命令的程序,以获取用户的到期日期。例如:“网络用户justinb / domain”
该程序获取到期日期。我正在使用该到期日期并将其设置为变量dadd
在下面的示例中,我们假设给定的到期日期为1/10/2018。(注意:Windows不会在当月前加0)
import time
datd = "1/10/2018"
# places a 0 in front of the month if only 1 digit received for month
d = datd.split("/")
if len(d[0])==1:
datd="0"+datd
print("Changed to: " + datd)
myDate = (time.strftime("%m/%d/%Y"))
print ("This is today's date: " + myDate)
if datd <= myDate: # if datd is is earlier than todays date
print (" Password expired. ")
else:
print (" Password not expired. ")
input(" Press Enter to …Run Code Online (Sandbox Code Playgroud) 我对 python 比较陌生,我想知道永远不要写两次东西是否总是更好。我目前正在制作一个程序,其中在程序中的两个点可能需要将同一个句子保存到文件中(仅包含该句子)。
为此创建一个函数值得吗?我想知道,因为它现在需要 2 行代码,但是创建一个函数将使它成为 4 行(2 行用于定义函数,2 行用于调用它)。