我正在尝试实现快速模块化幂(b,k,m)的功能,该功能仅使用大约2k模块化乘法来计算b (2 k) mod m 。
我尝试了这个:
def FastModularExponentiation(b, k, m):
res = 1
b = b % m
while (k > 0):
if ((k & 1) == 1):
res = (res * b) % m
k = k >> 1
b = (b * b) % m
return res
Run Code Online (Sandbox Code Playgroud)
但是我仍然遇到相同的问题,即如果我尝试b = 2,k = 1,m = 10,我的代码将返回22。但是,正确的答案是:
2 ^(2 ^ 1)mod 10 = 2 ^ 2 mod 10 = 4
我找不到原因。
我正在尝试使用 Google Colab 中的 Tensorflow 实现 Tacotron 语音合成,使用此代码在 Github 中形成一个repo,下面是我的代码并且运行良好,直到使用 localhost 服务器的步骤,我如何在 Google 的笔记本中运行 localhost 服务器科拉布?
我的代码:
!pip install tensorflow==1.3.0
import tensorflow as tf
print("You are using Tensorflow",tf.__version__)
!git clone https://github.com/keithito/tacotron.git
cd tacotron
pip install -r requirements.txt
!curl https://data.keithito.com/data/speech/tacotron-20180906.tar.gz | tar xzC /tmp
!python demo_server.py --checkpoint /tmp/tacotron-20180906/model.ckpt #requires localhost
Run Code Online (Sandbox Code Playgroud)
不幸的是,从 Google Colab 以本地模式运行对我没有帮助,因为要做到这一点,我需要在我的机器中下载太大的数据。
下面是我的最后一个输出,在这里我应该打开localhost:8888来完成工作,所以正如我之前提到的,有没有办法在 Google Colaboratory 中运行 localhost?
我已VSCode配置为保存时格式化,并配置为延迟后自动保存,如下代码片段所示
{
...
"editor.formatOnSave": true,
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 1000,
...
}
Run Code Online (Sandbox Code Playgroud)
但是,只有当我显式保存时,它才不会在自动保存时格式化control+S
我怎样才能让它自动完成呢?
我正在尝试运行一个简单的 Cartopy 示例:
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
plt.show()
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误:
几何图形必须是点或线串
python: geos_ts_c.cpp:4179: int GEOSCoordSeq_getSize_r(GEOSContextHandle_t, const geos::geom::CoordinateSequence*, unsigned int*): Assertion0 != cs' failed`。
我使用 miniconda3 安装了 Cartopy:conda install -c conda-forge cartopy
我还尝试使用 pip (在虚拟环境中)安装 Cartopy,但出现了相同的错误。我的操作系统是 Debian Buster。
任何想法?
我正在尝试在我的计算机中实现此代码,我面临的问题是运行以下代码时出现错误:
fashion_mnist = keras.datasets.fashion_mnist
(X_train_full, y_train_full), (X_test, y_test) = (fashion_mnist.load_data())
X_valid, X_train = X_train_full[:5000], X_train_full[5000:]
y_valid, y_train = y_train_full[:5000], y_train_full[5000:]
Run Code Online (Sandbox Code Playgroud)
错误:
~\Anaconda3\lib\site-packages\tensorflow_core\python\keras\utils\data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir)
251 urlretrieve(origin, fpath, dl_progress)
252 except HTTPError as e:
--> 253 raise Exception(error_msg.format(origin, e.code, e.msg))
254 except URLError as e:
255 raise Exception(error_msg.format(origin, e.errno, e.reason))
Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz: 403 -- Forbidden
Run Code Online (Sandbox Code Playgroud)
但是如果我尝试单独下载数据,它不会给出禁止的错误,我尝试加载数据而不从谷歌下载,但又出现了另一个错误
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-13-68fe7d0ac27a> …Run Code Online (Sandbox Code Playgroud) 我在reddit遇到了一个编程问题(看一下问题的链接)
这是 Python 中的解决方案之一:
s="112213"
k=2
result=0
for i in range(len(s)):
num_seen = 0
window = {}
for ind in range(i, len(s)):
if not s[ind] in window:
num_seen += 1
window[s[ind]] = 1
else:
window[s[ind]] += 1
if window[s[ind]] == k:
num_seen -= 1
if num_seen == 0:
result +=1
elif window[s[ind]] > k:
break
print(result)
Run Code Online (Sandbox Code Playgroud)
我已经尝试将此解决方案移植到 Raku 中,这是我的代码:
my @s=<1 1 2 2 1 3>;
my $k=2;
my $res=0;
for ^@s {
my $seen = 0;
my …Run Code Online (Sandbox Code Playgroud) 我正在将XGBRegressor与 Pipeline 一起使用。管道包含预处理步骤和模型(XGBRegressor)。
以下是完整的预处理步骤。(我已经定义了numeric_cols和cat_cols)
numerical_transfer = SimpleImputer()
cat_transfer = Pipeline(steps = [
('imputer', SimpleImputer(strategy = 'most_frequent')),
('onehot', OneHotEncoder(handle_unknown = 'ignore'))
])
preprocessor = ColumnTransformer(
transformers = [
('num', numerical_transfer, numeric_cols),
('cat', cat_transfer, cat_cols)
])
Run Code Online (Sandbox Code Playgroud)
最终的管道是
my_model = Pipeline(steps = [('preprocessor', preprocessor), ('model', model)])
当我尝试在不使用Early_stopping_rounds 的情况下进行拟合时,代码工作正常。
(my_model.fit(X_train, y_train))
但是当我使用如下所示的Early_stopping_rounds时,我收到错误。
my_model.fit(X_train, y_train, model__early_stopping_rounds=5, model__eval_metric = "mae", model__eval_set=[(X_valid, y_valid)])
我收到错误:
model__eval_set=[(X_valid, y_valid)]) and the error is
ValueError: DataFrame.dtypes for data must be …Run Code Online (Sandbox Code Playgroud) 我创建了一个API端点,当用户尝试搜索时返回产品标题。现在在前端,当在输入字段上输入一些按键时,我将对该端点进行 API 调用。所以我将该组件编写React为基于类的组件。它工作正常。但是现在我想React通过使用React钩子在较新版本中转换该组件。
我的基于类的实现工作正常。我所做的是当用户输入一些按键时。我debounce即延迟作为参数传递的函数的执行。该函数handleSearchChange()从字段中获取值并检查value字符串是否大于 1 个字符,然后在指定的延迟后进行 API 调用,作为响应返回一些结果。
服务器从以下数据中过滤结果:
[
{
"title": "Cummings - Nikolaus",
"description": "Assimilated encompassing hierarchy",
"image": "https://s3.amazonaws.com/uifaces/faces/twitter/michalhron/128.jpg",
"price": "$20.43"
},
{
"title": "Batz, Kiehn and Schneider",
"description": "Public-key zero tolerance portal",
"image": "https://s3.amazonaws.com/uifaces/faces/twitter/attacks/128.jpg",
"price": "$58.97"
},
{
"title": "Borer, Bartell and Weber",
"description": "Programmable motivating system engine",
"image": "https://s3.amazonaws.com/uifaces/faces/twitter/craighenneberry/128.jpg",
"price": "$54.51"
},
{
"title": "Brekke, Mraz and Wyman",
"description": "Enhanced …Run Code Online (Sandbox Code Playgroud) 我用较小的数据集训练了以下 CNN 模型,因此它确实过拟合:
model = Sequential()
model.add(Conv2D(32, kernel_size=(3,3), input_shape=(28,28,1), padding='same'))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(Conv2D(32, kernel_size=(3,3), padding='same'))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Dropout(0.4))
model.add(Flatten())
model.add(Dense(512))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))
model.compile(loss="categorical_crossentropy", optimizer=Adam(), metrics=['accuracy'])
Run Code Online (Sandbox Code Playgroud)
该模型有很多可训练的参数(超过 300 万个,这就是为什么我想知道我是否应该像下面这样使用额外的 MaxPooling 来减少参数的数量?
Conv - BN - Act - MaxPooling - Conv - BN - Act - MaxPooling - Dropout - Flatten
或者有一个额外的 MaxPooling 和 Dropout,如下所示?
Conv - BN - Act - MaxPooling - Dropout - Conv - BN - Act - MaxPooling - Dropout - Flatten
我试图了解 MaxPooling …
我有一个注册流程,它工作正常并且是多步骤的:
现在的流程是,完成所有步骤后,将创建一个新用户,如果用户名已经存在,那么在最后一步中我会收到一条错误消息,表明该用户已经存在。现在我需要改变这个流程。输入联系方式(电子邮件)后,我想检查该用户是否存在。如果它存在,那么我需要显示在第一步本身的最后一步中显示的错误消息,并阻止旅程移动到下一步。
为了实现这一目标,我所做的是:
创建了一个 TP,使用电子邮件读取用户详细信息,并将其作为第一步的验证技术配置文件:
<TechnicalProfile Id="AAD-CheckUserExist">
<Metadata>
<Item Key="Operation">Read</Item>
<Item Key="RaiseErrorIfClaimsPrincipalAlreadyExists">true</Item>
</Metadata>
<IncludeInSso>false</IncludeInSso>
<InputClaims>
<InputClaim ClaimTypeReferenceId="email" PartnerClaimType="signInNames.emailAddress" />
</InputClaims>
<OutputClaims>
<!-- Required claims -->
<OutputClaim ClaimTypeReferenceId="objectId" />
<OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="localAccountAuthentication" />
<!-- Optional claims -->
<OutputClaim ClaimTypeReferenceId="userPrincipalName" />
<OutputClaim ClaimTypeReferenceId="displayName" />
<OutputClaim ClaimTypeReferenceId="accountEnabled" />
<OutputClaim ClaimTypeReferenceId="otherMails" />
<OutputClaim ClaimTypeReferenceId="signInNames.emailAddress"/>
<OutputClaim ClaimTypeReferenceId="signInNames.phoneNumber"/>
<OutputClaim ClaimTypeReferenceId="givenName" />
<OutputClaim ClaimTypeReferenceId="surname" />
</OutputClaims>
<IncludeTechnicalProfile ReferenceId="AAD-Common" />
</TechnicalProfile>
Run Code Online (Sandbox Code Playgroud)
并添加<Item Key="RaiseErrorIfClaimsPrincipalAlreadyExists">true</Item>到<Metadata>.
以下是验证配置文件部分:
<TechnicalProfile Id="AAD-CheckUserExist">
<Metadata>
<Item Key="Operation">Read</Item>
<Item Key="RaiseErrorIfClaimsPrincipalAlreadyExists">true</Item> …Run Code Online (Sandbox Code Playgroud) python ×5
tensorflow ×2
autosave ×1
azure-ad-b2c ×1
cartopy ×1
cryptography ×1
dropout ×1
identity-experience-framework ×1
keras ×1
max-pooling ×1
mnist ×1
pipeline ×1
raku ×1
reactjs ×1
typescript ×1
xgboost ×1
xml ×1