解决办法:
可以尝试使用的是pd.Series.value_counts():
# Mock df
df = pd.DataFrame({key:np.random.randint(1, 6, 5) for key in "abcde"})
a b c d e
0 5 5 2 4 5
1 1 1 2 3 4
2 1 1 1 4 4
3 2 1 1 1 4
4 5 2 4 5 3
cols = ["a", "b", "c"]
new_df = pd.concat([df[c].value_counts() for c in cols], 1).fillna(0).astype(int)
print(new_df)
a b c
1 2 3 2
2 1 1 2
4 0 0 1
5 2 1 0
啊啊啊啊啊吖
2019-02-18
一种选择是使用未记录的命令resetplotview。
来自doc resetplotview:
限内部使用。在将来的版本中可能会删除此功能。
在xlim命令之前调用此函数。
figure(1);
x = 0:0.1:6
plot( x, sin(x) ); % Example plot, x axis range [0, 6]
resetplotview( gca, 'InitializeCurrentView' ) % Ensure we can reset the zoom
xlim( [2, 4] ); % 'Zoom' into the x axis range [2, 4]
这具有所需的结果,其中单击“重置为原始视图”缩小到x范围[0, 6],但最初显示的x范围是[2, 4]。
因为此函数未记录,所以具有内部的上下文可能是有用的。您可以edit resetplotview查看'InitializeCurrentView'选项的实现位置。从本质上讲,它可以setappdata用来定义'matlab_graphics_resetplotview'属性,特别是XLim属性为'auto'。如果resetplotview函数已折旧,您可以手动执行此操作。
啊啊啊啊啊吖
2019-02-16
各种方式:
1)将总和计算为一对一Nmax:
Nmax = 30;
Vijn = @(i,j,n) R*((1-(-1)^n)/(n^4 *pi^4)*sin((n*pi*c*j)/L)*sin((n*pi*i)/L));
i = 1:31;
j = 1:50;
n = 1:Nmax;
[I,J,N] = ndgrid(i,j,n);
V = arrayfun(Vijn,I,J,N);
Vc = cumsum(V,3);
% now Vc(:,:,k) is sum_n=1^{k+1} V(i,j,n)
figure(1);clf;imagesc(Vc(:,:,end));
2)无限循环
n = 1;
V = 0;
i = 1:31;
j = 1:50;
[I,J] = meshgrid(i,j);
while true
V = V + R*((1-(-1)^n)/(n^4 *pi^4)*sin((n*pi*c*J)/L).*sin((n*pi*I)/L));
n = n + 1;
figure(1);clf;
imagesc(V);
title(sprintf('N = %d',n))
drawnow;
pause(0.25);
end
啊啊啊啊啊吖
2019-02-15
尝试寻找bar功能
示例代码段
g1 = [10,10,20];
g2 = [15,10,8];
algStr = sprintfc('Algorithm %d',1:3);
bar(categorical({'Group1','Group2'}),[g1;g2])
legend(algStr)
啊啊啊啊啊吖
2019-02-15
zxq997
2019-02-14
其实数学专业说法叫多元函数哈,R多元方程组求解可使用dfsane,nleqslv
包,用法是:
dfsane(par, fn, method=2, control=list(),
quiet=FALSE, alertConvergence=TRUE, ...)
yaffawang
2019-02-13
解决办法:
可以在一个中使用的逻辑 groupby
import pandas as pd
df = pd.DataFrame({"ID":['xyz', 'pqr', 'xyz', 'rst'],
"event_type":['a', 'b', 'b', 'a']})
df.groupby("ID")\
.apply(lambda x: not (len(x)==1 and
not "a" in x["event_type"].values))
可以通过打印检查。最后使用此过滤器即可运行
df = df.groupby("ID")\
.filter(lambda x: not (len(x)==1 and
not "a" in x["event_type"].values))\
.reset_index(drop=True)
啊啊啊啊啊吖
2019-02-13
csv标准模块就足够了。您只需要迭代策略以将描述提取为数据库值,然后在policyItems上提取用户:
with open("Ranger_Policies_20190204_195010.json") as file:
jsonDF = json.load(file)
with open("outputfile.csv", newline='') as fd:
wr = csv.writer(fd)
_ = wr.writerow(('Database name', 'Users', 'Description'))
for policy in js['policies']:
desc = policy['description']
db_values = policy['resources']['database']['values']
for item in policy['policyItems']:
users = item['users']
for user in users:
for db in db_values:
if db != '*':
_ = wr.writerow((db, user, desc))
啊啊啊啊啊吖
2019-02-13
小木虫02
2019-02-02
朝阳Tim
2019-01-31
X = x_test[i:i+1]
# Visualize weights
W = model.layers[1].get_weights()[0][:,:,0,:]
w1=W.reshape(16,3,3)
W = np.squeeze(w1)
print("W shape : ", W.shape)
for i in range(0,16):
plt.subplot(4,4,i+1)
plt.imshow(w1[i,:,:], interpolation='nearest',cmap='gray')
plt.show()
W = model.layers[2].get_weights()[0][:,:,0,:]
w2=W.reshape(8,3,3)
W = np.squeeze(w2)
print("W shape : ", W.shape)
for i in range(0,8):
plt.subplot(4,4,i+1)
plt.imshow(w2[i,:,:], interpolation='nearest',cmap='gray')
plt.show()
啊啊啊啊啊吖
2019-01-28
PGC123
2019-01-25