我有一些我想要使用的图像,问题是有两种图像都是106 x 106像素,一些是彩色的,一些是黑色和白色.
一个只有两(2)个维度:
(106106)
和一个三(3)
(106,106,3)
有没有办法可以去掉这最后一个维度?
我试过np.delete,但它似乎没有用.
np.shape(np.delete(Xtrain[0], [2] , 2))
Out[67]: (106, 106, 2)
Run Code Online (Sandbox Code Playgroud) 以下示例: http://scikit-learn.org/stable/modules/ generated/sklearn.linear_model.Lasso.html
from sklearn import linear_model
clf = linear_model.Lasso(alpha=0.1)
clf.fit([[0,0], [1, 1], [2, 2]], [0, 1, 2])
clf.predict(np.array([0,0]).reshape(1,-1))
Out[13]: array([ 0.15])
Run Code Online (Sandbox Code Playgroud)
我可以将预测作为分类而不是回归吗?换句话说,当我给它一个输入时,我想要一个分类的输出。
我要做的是: 在C中编写一个程序,打开一个任意大小的文件并读取其内容.一旦读取内容,它将在AES 256 CBC中加密它们并将密文保存到一个名为密文的文件中.保存后,它将关闭这两个文件.然后将打开刚刚保存的文件中的密文并解密密文并将其保存到名为decrypted的文件中.
我的问题: 似乎永远不会解密我的密文.我得到垃圾,我不知道我做错了什么.请帮忙.
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <openssl/evp.h>
#include <openssl/aes.h>
void encrypt(FILE *ifp, FILE *ofp)
{
//Get file size
fseek(ifp, 0L, SEEK_END);
int fsize = ftell(ifp);
//set back to normal
fseek(ifp, 0L, SEEK_SET);
int outLen1 = 0; int outLen2 = 0;
unsigned char *indata = malloc(fsize);
unsigned char *outdata = malloc(fsize*2);
unsigned char ckey[] = "thiskeyisverybad";
unsigned char ivec[] = "dontusethisinput";
//Read File
fread(indata,sizeof(char),fsize, ifp);//Read Entire File
//Set up encryption
EVP_CIPHER_CTX ctx;
EVP_EncryptInit(&ctx,EVP_aes_256_cbc(),ckey,ivec);
EVP_EncryptUpdate(&ctx,outdata,&outLen1,indata,fsize); …
Run Code Online (Sandbox Code Playgroud) 我想将输出 np 数组与功能相匹配以创建新的 pandas 数据框
这是我的管道:
from sklearn.pipeline import Pipeline
# Categorical pipeline
categorical_preprocessing = Pipeline(
[
('Imputation', SimpleImputer(missing_values=np.nan, strategy='most_frequent')),
('Ordinal encoding', OrdinalEncoder(handle_unknown='use_encoded_value', unknown_value=-1)),
]
)
# Continuous pipeline
continuous_preprocessing = Pipeline(
[
('Imputation', SimpleImputer(missing_values=np.nan, strategy='mean')),
('Scaling', StandardScaler())
]
)
# Creating preprocessing pipeline
preprocessing = make_column_transformer(
(continuous_preprocessing, continuous_cols),
(categorical_preprocessing, categorical_cols),
)
# Final pipeline
pipeline = Pipeline(
[('Preprocessing', preprocessing)]
)
Run Code Online (Sandbox Code Playgroud)
我是这样称呼它的:
X_train = pipeline.fit_transform(X_train)
X_val = pipeline.transform(X_val)
X_test = pipeline.transform(X_test)
Run Code Online (Sandbox Code Playgroud)
这是我在尝试获取功能名称时得到的结果:
pipeline['Preprocessing'].transformers_[1][1]['Ordinal encoding'].get_feature_names()
Run Code Online (Sandbox Code Playgroud)
出去:
AttributeError: 'OrdinalEncoder' object has no …
Run Code Online (Sandbox Code Playgroud) 我有两个系列,一个模型和一个论文集。我需要能够匹配他们两个的字段。它们有一个共同的字段,称为引用,其中包含一个标识符。
我想匹配具有以下内容的文档
“作者”:来自论文集“细胞类型”的“Migliore M”:来自模型集的“海马CA3锥体细胞”
这是我的代码的样子:
pipeline = [{'$lookup':
{'from' : 'models',
'localField' : 'references',
'foreignField' : 'references',
'as' : 'cellmodels'}},
{'$match':
{'authors' : 'Migliore M', 'cellmodels.celltypes' : 'Hippocampus CA3 pyramidal cell'}},
]
for doc in (papers.aggregate(pipeline)):
pprint (doc)
Run Code Online (Sandbox Code Playgroud)
我没有结果。
我注意到,如果我不在 match 参数中调用 cellmodels.celltypes,它会找到匹配 Migliore M 的论文。我怎样才能让它也匹配 celltype:'Hippocampus CA3 pyramidal cell' from the models collection in this询问?
我正在尝试做的是:如何处理用户使用 Web 套接字与应用程序断开连接,但仍允许连接到服务器的其他用户继续?如果我运行此命令,所有用户都可以连接,但是当一个用户断开连接时,服务器会引发异常:
websockets.exceptions.ConnectionClosed:WebSocket 连接已关闭:代码 = 1001(消失),无缘无故
这是我的代码:
#!/usr/bin/env python
import asyncio
import websockets
import json
import ssl
import pathlib
users = {}
connected = set()
async def sendTo(websocket, message):
await websocket.send(json.dumps(message))
async def signaling(websocket, path):
while(True):
#get message from client
message = await websocket.recv()
#decode message
try:
data = json.loads(message)
except:
print("Not valid json")
print(message)
if data['type'] == "login":
if data['name'] in users:
await sendTo(websocket,{"type": "login",
"Success":False})
print("sentTo Failed, username already taken")
else:
users[data['name']] = {"websocket": websocket}
await sendTo(websocket, …
Run Code Online (Sandbox Code Playgroud) 怎么了:
我很好奇我应该如何设置我的管道?我正在通过 webrtc 向浏览器发送一个原始的 h264 流。我看到了一个通过 webrtc 发送原始 vp8 的示例。
症状:
我问的原因是我的视频流展示了伪像(视频乱码?)。视频将播放不到一秒钟(几帧)并停止约 5 秒钟,然后再播放几帧。我正在尝试从我的树莓派上运行它。
我试过的:
我使用笔记本电脑尝试了完全相同的脚本,并且运行良好。我不确定为什么我会从一台设备上得到乱码视频,而从另一台设备上却没有?
我的第一个想法是,这可能与我在 pi 上查看顶部并获得 60%-100+% 的 CPU 瓶颈有关。(其动态编码 h264)。但可能是它没有正确缓冲吗?我尝试从 rpi 相机捕获 h264 流,并且 cpu 非常低,但存在相同的问题。
更有趣的是,当我使用 firefox 时,它似乎可以正常工作(视频停顿 < 1 秒但继续)。至于为什么我不确定。
我在笔记本电脑和 pi 上都使用 gstreamer 1.15(git)
这是我的管道:
PIPELINE_DESC = '''
webrtcbin name=sendrecv bundle-policy=max-bundle
videotestsrc is-live=true ! x264enc ! h264parse ! rtph264pay config-interval=-1 !
queue ! application/x-rtp,media=video,encoding-name=H264,payload=96 ! rtpjitterbuffer ! sendrecv.
audiotestsrc is-live=true wave=red-noise ! audioconvert ! audioresample ! queue ! opusenc ! rtpopuspay …
Run Code Online (Sandbox Code Playgroud) 背景:
遵循这个问题,当使用 bert 对序列进行分类时,模型使用表示分类任务的“[CLS]”标记。据该论文称:
每个序列的第一个标记始终是一个特殊的分类标记([CLS])。与该标记对应的最终隐藏状态用作分类任务的聚合序列表示。
查看 Huggingfaces 存储库,他们的 BertForSequenceClassification 使用 bert pooler 方法:
class BertPooler(nn.Module):
def __init__(self, config):
super().__init__()
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
self.activation = nn.Tanh()
def forward(self, hidden_states):
# We "pool" the model by simply taking the hidden state corresponding
# to the first token.
first_token_tensor = hidden_states[:, 0]
pooled_output = self.dense(first_token_tensor)
pooled_output = self.activation(pooled_output)
return pooled_output
Run Code Online (Sandbox Code Playgroud)
我们可以看到他们采用第一个标记(CLS)并将其用作整个句子的表示。具体来说,他们执行的操作hidden_states[:, 0]
看起来很像从每个状态中获取第一个元素,而不是获取第一个标记隐藏状态?
我的问题:
我不明白的是他们如何将整个句子的信息编码到这个标记中?CLS 标记是一个常规标记,它有自己的嵌入向量来“学习”句子级别表示吗?为什么我们不能只使用隐藏状态的平均值(编码器的输出)并用它来分类?
编辑:经过一番思考:因为我们使用 CLS 令牌隐藏状态来预测,所以 CLS 令牌嵌入是否正在接受分类任务的训练,因为这是用于分类的令牌(因此是导致错误的主要因素)哪个会传播到它的权重?)
python transformer-model bert-language-model huggingface-transformers
我有一个XSD模式文件,我想解析并回显它包含的元素,如果可能的话,还可以显示每个元素所具有的子对象。我看过一些示例,其中最好的示例是: 在PHP中将XSD文件转换为数组
我试了一下,即使更改了xpaths和文件位置中的xs:部分,它也给了我一个空数组。有没有正确的方法来解析XSD文件并在PHP中显示其元素?
为了消除任何困惑,我想说的是:
可以说这是我正在尝试加载和显示其元素的XSD(来自上面的链接):
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string"/>
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
如我们所见,有一个名称为“ shiporder”的元素,它有一些子元素,如果我没记错的话,它是具有字符串类型的“ orderperson”,还有一个“ shipto”,其子元素是:字符串类型的“”,“地址”,“城市”,“国家”。
我想做的就是简单地打印出“ shiporder”有孩子“ orderperson”和“ shipto”“ shipto”有孩子“ name”,“ address”,“ city”和“ country”。
我怎样才能做到这一点?我应该使用下面描述的方法吗: …
我究竟做错了什么?
> crossprod(1:3,4:6)
[,1]
[1,] 32
Run Code Online (Sandbox Code Playgroud)
根据这个网站:http://onlinemschool.com/math/assistance/vector/multiply1/
它应该给:
{-3; 6; -3}
Run Code Online (Sandbox Code Playgroud)
另请参阅什么是R的交叉产物功能?
python ×5
scikit-learn ×2
aes ×1
arrays ×1
c ×1
cryptography ×1
encryption ×1
gstreamer ×1
mongodb ×1
numpy ×1
openssl ×1
pandas ×1
php ×1
pymongo ×1
r ×1
webrtc ×1
websocket ×1
xml ×1
xml-parsing ×1
xsd ×1