我正在使用 python 测试与 mysql 服务器的连接。我需要 ssh 进入服务器并建立 mysql 连接。以下代码有效:
from sshtunnel import SSHTunnelForwarder
import pymysql
import mysql.connector
with SSHTunnelForwarder((ssh_host, 22), ssh_username=ssh_user, ssh_password=ssh_password,
remote_bind_address=("127.0.0.1", 3306)) as tunnel:
config = {
'user': user,
'password': password,
'host': tunnel.local_bind_host,
'port': tunnel.local_bind_port,
'database': db
}
conn = pymysql.connect(**config)
query = '''SELECT VERSION();'''
data = pd.read_sql_query(query, conn)
print(data)
connection.close()
Run Code Online (Sandbox Code Playgroud)
但是,当使用mysql.connector而不是pymysql如下所示时:
with SSHTunnelForwarder((ssh_host, 22), ssh_username=ssh_user, ssh_password=ssh_password,
remote_bind_address=("127.0.0.1", 3306)) as tunnel:
config = {
'user': user,
'password': password,
'host': tunnel.local_bind_host,
'port': tunnel.local_bind_port,
'database': db …Run Code Online (Sandbox Code Playgroud) 该displs从参数MPI_Scatterv()函数被认为是一个“整数阵列(的长度组大小)。加入我指定位移(相对于sendbuf从中取传出数据处理I”。比方说,然后我有sendcounts争论
int sendcounts[7] = {3, 3, 3, 3, 4, 4, 4};
Run Code Online (Sandbox Code Playgroud)
我对此进行推理的方式是,displs数组应始终以0开头,因为第一个条目的位移相对于sendbuf,所以在上面的示例中displs应类似于:
int displs[7] = {0, 3, 6, 9, 13, 17, 21};
Run Code Online (Sandbox Code Playgroud)
那是对的吗?我知道这是一个微不足道的问题,但是由于某种原因,网络根本没有帮助。那里没有很好的例子,因此是我的问题。
我想给a textView内部的动画,recyclerView以便在调用时向上过渡notifyItemChanged(position)。这是我的onBindViewholder(),当适配器发生更改时,它会自动被调用:
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
if (unfoldedIndexes.contains(position)) { // if already unfolded
bindUnfoldedState(holder, holder.getLayoutPosition());
}else{ // show the folded state}
}
public void bindUnfoldedState(ViewHolder holder, int position){
if(lc.isBtnEnabled()){
holder.Price.setText("text");
holder.Price.animate().alpha(1.0f).setDuration(500);
holder.Price.animate().translationY(-38).setDuration(500);
holder.checkText.animate().translationY(38).setDuration(500);
}else {
holder.Price.animate().alpha(0.0f).setDuration(500);
holder.Price.animate().translationY(0).setDuration(500);
holder.checkText.animate().translationY(0).setDuration(500);
}
}
Run Code Online (Sandbox Code Playgroud)
我notifyItemChanged()被这样称呼fragment onClick:
ok.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
// some changes to the data
adapter.getLcns().get(Position).setBtnEnabled(true);
adapter.notifyItemChanged(Position);
}
}
Run Code Online (Sandbox Code Playgroud)
isBtnEnabled()如果etBtnEnabled(true)调用s …
我使用elasticsearch实例作为 nosql 数据库。这是brew在 mac os 上安装的。
我就是这样开始的elasticsearch。
brew services start elasticsearch
Run Code Online (Sandbox Code Playgroud)
我想知道是否有一个brew 命令(或其他命令)可以让我知道实例elasticsearch是否打开。
最终我想运行一个执行以下操作的bash 脚本:
If elasticsearch is off:
Turn on elastiscearch
Proceed
Else:
Proceed
Run Code Online (Sandbox Code Playgroud) 我正在使用 djangorest-auth来allauth验证用户身份。成功注册和电子邮件验证后,我实现了一个登录视图,其子类rest-auth.views.LoginView如下所示:
class ThLoginView(LoginView):
def get(self, request):
form = CustomUserLoginForm()
return render(request, "users/login.html", context={"form": form})
Run Code Online (Sandbox Code Playgroud)
用我自己的形式:
class CustomUserLoginForm(AuthenticationForm):
class Meta:
model = CustomUser
fields = ('email',)
Run Code Online (Sandbox Code Playgroud)
问题是当我登录时出现以下错误:
DoesNotExist at /users/login/
EmailAddress matching query does not exist.
Run Code Online (Sandbox Code Playgroud)
我改变的另一件重要的事情是我使用电子邮件作为注册/登录而不是用户名:
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_UNIQUE_EMAIL = True
Run Code Online (Sandbox Code Playgroud)
我的user模型AbstractBaseUser像这样覆盖:
class CustomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=254, unique=True)
name = models.CharField(max_length=254, null=True, blank=True)
username = models.CharField(max_length=254, blank=True) …Run Code Online (Sandbox Code Playgroud) django django-models django-authentication django-rest-framework django-rest-auth
我正在使用python requests模块,我正在获取一个URL.
response = requests.get(url)
此网址有一组标题,其中有时会出现一个特定标题,有时则不存在.如果它在那里我想得到这个标题的值.我在用
retry_after = response.headers['Retry-After']
Run Code Online (Sandbox Code Playgroud)
但是当标题不存在时会抛出异常.我想要的是这样的
If this header exists ( if header is not None)
retry_after = response.header['Retry_After']
Run Code Online (Sandbox Code Playgroud)
如何用python实现这一目标 requests
我有一个超过 13 列的竖线分隔数据文件。总文件大小超过 100 MB。我正在阅读每一行,将字符串拆分为 astd::vector<std::string>以便我可以进行计算。我对文件中的所有行重复此过程,如下所示:
string filename = "file.dat";
fstream infile(filename);
string line;
while (getline(infile, line)) {
string item;
stringstream ss(line);
vector<string> splittedString;
while (getline(ss, item, '|')) {
splittedString.push_back(item);
}
int a = stoi(splittedString[0]);
// I do some processing like this before some manipulation and calculations with the data
}
Run Code Online (Sandbox Code Playgroud)
然而,这非常耗时,而且我很确定这不是读取 CSV 类型文件的最优化方式。如何改进?
我尝试使用该boost::split函数而不是 while 循环,但实际上它更慢。
我正在使用具有自定义损失函数的 keras,如下所示:
def custom_fn(y_true, y_pred):
# changing y_true, y_pred values systematically
return mean_absolute_percentage_error(y_true, y_pred)
Run Code Online (Sandbox Code Playgroud)
然后,我打电话model.compile(loss=custom_fn)和model.fit(X, y,..validation_data=(X_val, y_val)..)
Keras 然后保存loss并保存val_loss在模型历史中。作为健全性检查,当模型完成训练时,我正在使用,model.predict(X_val)因此我可以custom_fn使用经过训练的模型手动计算验证损失。
我正在使用此回调保存具有最佳时代的模型:
callbacks.append(ModelCheckpoint(path, save_best_only=True, monitor='val_loss', mode='min'))
Run Code Online (Sandbox Code Playgroud)
所以在计算这个之后,验证损失应该与 kerasval_loss的最佳时期的值相匹配。但这并没有发生。
作为解决这个问题的另一种尝试,我也在这样做:
model.compile(loss=custom_fn, metrics=[custom_fn])
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,val_loss并val_custom_fn没有匹配(无论是loss或loss_custom_fn就此而言)。
这真的很奇怪,我custom_fn的本质上是 keras 内置mape的y_true并且y_pred稍微被操纵。这里发生了什么?
PS:我使用的LSTM层是层和最后Dense一层。但我认为这些信息与问题无关。我也使用正则化作为超参数,但不使用 dropout。
甚至删除custom_fn和使用 keras 内置mape的损失函数和度量,如下所示:
model.compile(loss='mape', metrics=['mape'])
Run Code Online (Sandbox Code Playgroud)
为简单起见,删除 …
我有一个elasticsearch索引(仅 150kb),我想在 kibana 中可视化。在进入堆栈管理 > 索引模式 > 生成新索引模式后,会抛出 429(请求过多)错误。这是来自浏览器:
Failed to load resource: http://localhost:5601/api/saved_objects/index-pattern the server responded with a status of 429 (Too Many Requests)
Run Code Online (Sandbox Code Playgroud)
为什么会这样?我关闭了 elasticsearch 和 kibana 并重新打开,但错误仍然存在。
我有一个numpy.ndarray类似于此的大型数据集:
array([[ -4, 5, 9, 30, 50, 80],
[ 2, -6, 9, 34, 12, 7],
[ -4, 5, 9, 98, -21, 80],
[ 5, -9, 0, 32, 18, 0]])
Run Code Online (Sandbox Code Playgroud)
我想删除重复的行,其中第 0、1、2 和 5 列相等。即在上述矩阵上,响应将是:
-4, 5, 9, 30, 50, 80
2, -6, 9, 34, 12, 7
5, -9, 0, 32, 18, 0
Run Code Online (Sandbox Code Playgroud)
numpy.unique做了一些非常相似的事情,但它只在所有列(轴)上找到重复项。我只想要特定的列。如何解决这个问题numpy?我找不到任何像样的numpy算法来做到这一点。有没有更好的模块?
python ×4
c++ ×2
android ×1
animation ×1
bash ×1
c ×1
curl ×1
django ×1
homebrew ×1
http-headers ×1
indexing ×1
keras ×1
kibana ×1
matrix ×1
mpi ×1
mysql ×1
numpy ×1
optimization ×1
performance ×1
pymysql ×1
python-3.x ×1
scatterview ×1
shell ×1
ssh ×1
string ×1
tensorflow ×1
vector ×1