I'd like to put True in the array in the if statement.
circle_lists=[0, 10, 30], [5, -10, 30], [100, 10, 20]]
overlap_list = [False]*len(circle_lists)
def calc(array):
for i in range (len(array)) :
for jin range(i+1,len(array)):
if(array[0][i]-array[0][j])**2+(array[1][i]-array[1][j])**2<(array[2][i]+array[2][j])**2:
overlap_list[i] = True
overlap_list[j] = True
calc(circle_lists)
print(overlap_list)
Executing this code
[True, True, True]
output.
if(array[0][i]-array[0][j])**2+(array[1][i]-array[1][j])**2<(array[2][i]+array[2][j])**2:
The conditional expression in is satisfied only when [0,10,30], [5, -10,30]
.
Therefore, I would like to print True, True, False.
The index for [[0, 10, 30], [5, -10, 30], [100, 10, 20]] matches the index for [False, False, False].So I want to make the output like that.
As the number of elements of circle_lists increases, I would like to avoid having to look at the elements of the second half.So I want to change False, False, False to True in the double for statement.
What is wrong?
Assume the following questions and answer them.
A considerable part is supplemented by speculation, so if you have any misunderstandings, please let us know by commenting.
If the question is as intended, please edit the body of the question.
Compare the elements of the array with each other and make a true decision if there is one element that matches the conditional expression.
The following two-dimensional array exists:
[ax,ay,az], [bx,by,bz], [cx,cy,cz],...]
ax to cz are any integer that includes 0 or negative, and the number of elements in the second dimension is fixed at 3.
Take out any element in the first dimension and compare each element with the following conditional expressions:
The conditional expressions are (bx-ax)**2+(by-ay)**2<(bz+az)**2
or (cx-ax)**2+(cy-ay)**2<(cz+az)**2
.
For [ax,ay,az]
, we are trying to create an array that stores True if any of the above conditions are met and False otherwise.
Consider an array of [0, 10, 30](A), [5, -10, 30](B), [100, 10, 20](C)]
.(Symbols in parentheses for the following description)
If A is evaluated by conditional expression to B and C, B is true, and if A and C are evaluated by B, A is true, but if A and B are evaluated by C, both A and B are false.
At this time, I would like to create a new array of [True (with elements that are true for A), True (like left for B), False (no elements that are true for C)
, but the code below does not provide the desired result.
How do I fix this?
circle_lists=[0, 10, 30], [5, -10, 30], [100, 10, 20]]
overlap_list = [False]*len(circle_lists)
def calc(array):
for i in range (len(array)) :
for jin range(i+1,len(array)):
if(array[0][i]-array[0][j])**2+(array[1][i]-array[1][j])**2<(array[2][i]+array[2][j])**2:
overlap_list[i] = True
overlap_list[j] = True
calc(circle_lists)
print(overlap_list)# [True, True, False] is expected, but [True, True, True]
For example, First of all, please check if the usage of the subscript matches the intended code.(array[0][i]-array[0][j])**2+(array[1][i]-array[1][j])**2<(array[2][i]+array[2][j])**2
is the syntax of (ax-ay)**2+(bx-by)**2<code>
as the question asks.
By flipping the if statement subscripts like [0][i]
→[i][0]
, you can get the value you want as the elements of the array increase.circle_lists=[0, 10, 30], [5, -10, 30], [100, 10, 20]]
overlap_list = [False]*len(circle_lists)
def calc(array):
for i in range (len(array)) :
for jin range(i+1,len(array)):
if(array[i][0]-array[j][0])**2+(array[i][1]-array[j][1])**2<(array[i][2]+array[j][2])**2:
overlap_list[i] = True
overlap_list[j] = True
calc(circle_lists)
print(overlap_list)# [True, True, False]
550 PHP ssh2_scp_send fails to send files as intended
548 Understanding How to Configure Google API Key
540 Uncaught (inpromise) Error on Electron: An object could not be cloned
548 Who developed the "avformat-59.dll" that comes with FFmpeg?
550 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.