我写了这个函数:
def get_x_y_co(circles):
xc = circles[0] #x-co of circle (center)
yc = circles[1] #y-co of circle (center)
r = circles[2] #radius of circle
arr=[]
for i in range(360):
y = yc + r*math.cos(i)
x = xc+ r*math.cos(i)
x=int(x)
y=int(y)
#Create array with all the x-co and y-co of the circle
arr.append([x,y])
return arr
Run Code Online (Sandbox Code Playgroud)
'circles' 是一个数组 [X-center, Y-center, Radius]
我想提取圆圈中存在的整数分辨率的所有点。现在,我意识到我正在创建一组位于圆边界上的点,但我无法访问圆内的点。
我想只减小半径,然后对半径的所有值进行迭代,直到半径为 0
但我觉得有一种更有效的方法。欢迎任何帮助
我在这里的问题中犯了一个错误(错误的请求输入和预期输出): 比较字典,更新NOT覆盖值
我不是在寻找这种解决方案: 将2个词典与通用密钥结合使用 因此这个问题不是重复的
问题陈述:
要求的输入:
d1 = {'a': ['a'], 'b': ['b', 'c']}
d2 = {'b': ['c', 'd'], 'c': ['e','f']}
Run Code Online (Sandbox Code Playgroud)
预期的输出(我不在乎键/值的顺序!):
new_dict = {'a': ['a'], 'b': ['b', 'c', 'd'], 'c': ['e', 'f']}
Run Code Online (Sandbox Code Playgroud)
将2个词典与公共密钥结合在一起的解决方案 给出以下输出:
new_dict = {'a': ['a'], 'b': ['b', 'c', 'c', 'd'], 'c': ['e', 'f']}
Run Code Online (Sandbox Code Playgroud)
我不希望重复项被存储。
我的解决方案(它可以工作,但效率不高):
unique_vals = []
new_dict = {}
for key in list(d1.keys())+list(d2.keys()) :
unique_vals = []
try:
for val in d1[key]:
try:
for val1 in d2[key]: …
Run Code Online (Sandbox Code Playgroud) 问题:针对多个列值约束,提取特定列的值(在本例中为“评级”)。
从如下所示的 DataFrame 开始
我的数据如下:
userID movieID rating
0 196 242 3
1 186 302 3
2 22 377 1
Run Code Online (Sandbox Code Playgroud)
现在,我想提取以下案例的评级:
userID == 196
movieID == 242
Run Code Online (Sandbox Code Playgroud)
结果应该是 3。
我使用以下代码解决了这个问题: 但是这不是很有效。有人有更好的方法吗?
Run Code Online (Sandbox Code Playgroud)df.loc[df['userID'] == 196].where(df['movieID'] == 242).dropna()['rating']
这给了我 ID 为 242、用户 ID 为 196 的电影的评级。
所以我在阅读Java中的Json文件时遇到了麻烦.
它是一个Json文件,其内容采用以下格式:
{
"_id": 2864071,
"name": "Neustadt",
"country": "DE",
"coord": {
"lon": 12.56667,
"lat": 52.400002
}
}
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的代码:
package controllers;
@Named(value = "cityID")
@SessionScoped
public class getCityIDs implements Serializable {
public long getCityIDs(String name) {
//Read the json file
try {
FileReader reader = new FileReader(filePath);
JSONParser parser = new JSONParser();
JSONObject jsonObject = (JSONObject) parser.parse(reader);
// get a number from the JSON object
String travelName = (String) jsonObject.get("name");
if(travelName.equals(name)){
long id = (long) jsonObject.get("_id");
System.out.println(id);
return id;
} else …
Run Code Online (Sandbox Code Playgroud) 我想用ipywidgets创建一个交互式模块。到目前为止还不错,但是我被卡住了。我想根据特定情况隐藏某个ipywidget对象的可见性,并且我希望打印的文本显示在小部件上方并停留在该位置。
dropdown=widgets.Dropdown(
options={'Coffee machine': 1, 'Washing machine': 2, 'Water Heater': 3, 'Heating System': 4, 'Dryer': 5, 'Oven': 6, 'Microwave': 7, 'Other':8},
value=1,
description='Apparaat:',
)
text_new=widgets.Text()
def text_field(value):
if(value==8):
display(text_new)
text_new.on_submit(handle_submit)
else:
text_new.visible(False) #Doesn't work but I want something like this
print("Today you had an increase in electricity consumption, would you like to name this device?") #This just be above the dropdown menu and be stuck
i=widgets.interactive(text_field, value=dropdown)
display(i)
Run Code Online (Sandbox Code Playgroud)
现在的作用:在下拉菜单中选中“其他”时,将出现一个文本框,用户可以在其中键入内容。但是,当检查另一台计算机时,该文本框将停留在该位置。我只需要一个“隐藏”功能,但似乎找不到一个有效的功能。
同样,在下拉菜单中检查另一个选项后,打印消失,不再回来。
我正在尝试紧跟Toolbar
在顶部栏中的那一秒。基本上有一个Button
,当按下它时,窗口中会弹出一个条。用户应该能够阅读栏上的内容并可以按Button
。现在,我正在尝试在此处输入文字。但这似乎不起作用。
.java函数:(按下某个按钮时调用,显示工具栏)
public void showDialogue() {
//Set popupscherm as view
View v = getLayoutInflater().inflate(R.layout.popupscherm,null);
AlertDialog.Builder adb = new AlertDialog.Builder(GraphActivity.this);
adb.setView(v);
// Find the toolbar view inside the activity layout
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("test"); //Here it gives the error
AlertDialog alert = adb.create();
alert.show();
Run Code Online (Sandbox Code Playgroud)
popupscherm.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary">
</android.support.v7.widget.Toolbar>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
错误:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.Toolbar.setTitle(java.lang.CharSequence)' on …