我想了解创建句子的 fastText 向量的方式。根据这个问题309,通过平均单词的向量来获得句子的向量。
为了确认这一点,我编写了以下脚本:
import numpy as np
import fastText as ft
# Loading model for Finnish.
model = ft.load_model('cc.fi.300.bin')
# Getting word vectors for 'one' and 'two'.
one = model.get_word_vector('yksi')
two = model.get_word_vector('kaksi')
# Getting the sentence vector for the sentence "one two" in Finnish.
one_two = model.get_sentence_vector('yksi kaksi')
one_two_avg = (one + two) / 2
# Checking if the two approaches yield the same result.
is_equal = np.array_equal(one_two, one_two_avg)
# Printing the result.
print(is_equal)
# Result: …Run Code Online (Sandbox Code Playgroud) 我想在浏览片段中重新加载一些行数据.
基本上我想重置适配器数据而不会在浏览片段中产生类似闪存的效果.知道如何做到这一点?
类似于列表视图中的notifyDataSetChanged().
感谢名单
所以我想从 Spyder 迁移到 VSCode,我遇到了这个问题,我无法访问数据集,因为我的工作目录与数据集的路径不同。
launch.json不是为我自动生成的,因为我没有调试任何东西(我试过这个)。
如何在 VSCode 中将工作目录设置为始终是我要运行的 Python 文件的目录?(如果这是不好的做法,你能告诉我一个易于使用的配置吗?)我想为 VSCode 的 IPython 终端设置它。
在 2 个独立的容器内有 2 个 Flask 应用程序,我认为可以GET从一个容器运行请求并从第二个容器返回信息,但我得到了[Errno 111] Connection refused。通过以下设置:
应用程序1.py
@app.route('/get_message')
def get_message():
message = requests.get('http://web2:5001/return_message')
return message.text
if __name__ == '__main__':
app.run(host='0.0.0.0')
Run Code Online (Sandbox Code Playgroud)
应用程序2.py
@app.route('/return_message')
def return_message():
return 'the message'
if __name__ == '__main__':
app.run(host='0.0.0.0')
Run Code Online (Sandbox Code Playgroud)
docker-compose.yml
version: "3.7"
services:
web1:
build: ./web1
container_name: web1
ports:
- "5000:5000"
web2:
build: ./web2
container_name: web2
ports:
- "5001:5001"
Run Code Online (Sandbox Code Playgroud)
app1 的端点在访问http://127.0.0.1:5000/get_message时有效,但 Flask 返回:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='web2', port=5001): Max retries exceeded with url: /return_message (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at …Run Code Online (Sandbox Code Playgroud) 下面的代码片段在Java 1.8中运行良好,但不能与Java 11 SDK一起使用.
public static void main(String[] args) {
String jsonText = "{\"user\":{\"name\":\"mrhaki\",\"age\":38,\"interests\":[\"Groovy\",\"Grails\"]}}";
JsonSlurper jsonSlurper = new JsonSlurper();
Object result = jsonSlurper.parseText(jsonText);
Map jsonResult = (Map) result;
Map user = (Map) jsonResult.get("user");
String name = (String) user.get("name");
Integer age = (Integer) user.get("age");
List interests = (List) user.get("interests");
assert name.equals("mrhaki");
assert age == 38;
assert interests.size() == 2;
assert interests.get(0).equals("Groovy");
assert interests.get(1).equals("Grails");
}
Run Code Online (Sandbox Code Playgroud)
尝试在Java 11中运行上面的代码片段时,获得以下异常.
Exception in thread "main" java.lang.ClassCastException: class [B cannot be cast to class [C ([B and …Run Code Online (Sandbox Code Playgroud) 我知道调用wb.sheetnames返回每个工作表的字符串形式的名称列表,但是我看不到获取当前活动工作表的名称的方法。工作表模块中似乎没有可供引用的命名属性。
A1作为一个基本示例,我想将工作簿中每个工作表的工作表名称写入 cell ;
wb = openpyxl.load_workbook(filepath)
for sheet in wb.sheetnames:
ws.insert_rows(1)
ws.cell(row=1, column=1).value = sheet.name << Can I reference the active sheetname here with something similar?
Run Code Online (Sandbox Code Playgroud)
或者是否需要使用该wb.sheetnames方法并迭代每个方法?
wb = openpyxl.load_workbook(filepath)
names = [sheet for sheet in wb.sheetnames]
i = 0
for sheet in wb.sheetnames:
ws.insert_rows(1)
ws.cell(row=1, column=1).value = names[i]
i += 1
Run Code Online (Sandbox Code Playgroud) 我目前有一个包含不同概率的6x3矩阵.
在这种情况下,我的行有3个值,对应于我的样本最终属于某个类的概率.
我想要做的是为我的6个样本获得3个不同类别中的每一个.我担心我最终可能会重复一遍.
我注意到每个元素都lista包含6个值.有没有一种简单的方法可以摆脱可能的重复?
for combination in itertools.product(*probability):
q1 = np.prod((combination))
lista.append(q1)
print(combination)
i = i+1
print(i)
print(np.sum(lista))
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我在函数中使用 for 循环,并在此函数中传递列表,然后显示 plint(unused-variable)warning 并且他们没有给出正确的输出
def ff(f):
for i in f:
print (fruits)
fruits=["apple","banana","cherry"]
ff(fruits)
Run Code Online (Sandbox Code Playgroud)
=> unused variable 'i' pylint(unused-variable)
python ×6
python-3.x ×2
android-tv ×1
docker ×1
excel ×1
fasttext ×1
flask ×1
java-11 ×1
leanback ×1
openpyxl ×1