小编daw*_*999的帖子

寻找两个圆的交点

我试图在 Python(使用 Matplotlib)中找到两个圆圈之间的交点,但无法取回任何值。

我通过为每个单独的圆创建 X 和 Y 的列表来做到这一点(Matplotlib 在绘制圆时将第一个参数作为 X 值,第二个作为 Y 值),然后相应地将列表相交(例如, circle1 x 值与 circle2 x 值)。

import numpy
import math
import matplotlib.pyplot as plt
import random

def origin_circle():
    global x_points
    global y_points
    global r
    global n
    r=1
    n=2**16
    x_points=[(r*math.cos(t)) for t in numpy.linspace(0, 2*numpy.pi*r, n+1)]
    y_points=[(r*math.sin(t)) for t in numpy.linspace(0, 2*numpy.pi*r, n+1)]

def new_circle(x_offset, y_offset):
    global x_points1
    global y_points1
    x_points1=[x_offset+(r*math.cos(t)) for t in numpy.linspace(0, 2*numpy.pi*r, n+1)]
    y_points1=[y_offset+(r*math.sin(t)) for t in numpy.linspace(0, 2*numpy.pi*r, n+1)]

origin_circle()
new_center= random.randint(0, len(x_points)) …
Run Code Online (Sandbox Code Playgroud)

python set-intersection

5
推荐指数
1
解决办法
1万
查看次数

按特定字母拆分字符串,同时在字符串中保留它们

我正在尝试按特定字母分割字符串(在这种情况下:'r','g'和'b'),以便稍后我可以将它们附加到列表中.这里的问题是我希望将字母复制到列表中.

string = '1b24g55r44r'
Run Code Online (Sandbox Code Playgroud)

我想要的是:

[[1b], [24g], [55r], [44r]]
Run Code Online (Sandbox Code Playgroud)

python

1
推荐指数
1
解决办法
54
查看次数

(Python)将列表中的项目转换为列表

我想将列表中的项目作为列表存储(即每个二进制位将是新列表中的索引)但我似乎无法实现这一点:

encoded = []
for value in redChannelData:
    encoded1 = bin(value)[2:]
    encoded.append(encoded1)

redchannelbinarylist = [[] for binary in encoded] 

print(redchannelbinarylist)
print(encoded)
Run Code Online (Sandbox Code Playgroud)

产量

['101110', '110001', '110010', '110011', '110101', '110101', '110110', '111000', '111011', '111011', '111100', '111101', '111110', '111110', '1000000', '1000000', '1000001']
Run Code Online (Sandbox Code Playgroud)

我想要这样的东西:

[[1, 0, 1, 1, 1, 0], [1, 1, 0, 0, 0, 1], ...]
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
61
查看次数

从2个列表中连接n位置的字符串

我试图在2个列表的每个第n个位置连接字符串.但我似乎无法让它发挥作用

输入:

['57', '60', '55',..., '56']

['g', 'b', 'r',..., 'b']
Run Code Online (Sandbox Code Playgroud)

输出:

['57g', '60b', '55r',..., '56b']
Run Code Online (Sandbox Code Playgroud)

python

-1
推荐指数
1
解决办法
50
查看次数

标签 统计

python ×4

set-intersection ×1