Already have an account? Log in here.
When you need to do a repetitive task, like working through all elements in a list to find a prime or searching a map until you've found all of the gold, loops are a goto tool.
Use list comprehension to generate the list of all perfect numbers less than 10,000, \(\{P_1,P_2,\ldots,P_N\}\).
What is their sum \(\sum_i P_i\)?
Assumptions and Details
Already have an account? Log in here.
Suppose you're working on code for a molecular dynamics visualization. You need to represent various matrices, like the 3d rotation matrix, using Python lists. We can do so by using lists of lists.
For example, the matrix
\[A= \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \end{bmatrix} \]
is represented by
1 

and the matrix
\[B= \begin{bmatrix} 1 \\ 2 \\ 3 \\ \end{bmatrix} \]
would be
1 

The fragments below are designed to perform operations on matrices. Your task is to match the function bodies with the correct function definitions.
A:
1 2 

B:
1 2 3 

C:
1 2 3 

The function bodies are given by the following
1:
1 2 

2:
1 

3:
1 

Already have an account? Log in here.
In scientific computing, it is a common task to take the transpose of a matrix. The transpose of a matrix \(A\), \(A^T\), is found by turning all the rows of a matrix into columns and vice versa. More formally the transpose of a matrix \(A\) is found by reflecting \(A\) over its main diagonal.
For example, the transpose of
\[ A = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 1 & 9 \\ 8 & 0 & 1 \\ \end{bmatrix} \]
is given by
\[ A^T = \begin{bmatrix} 1 & 4 & 8 \\ 2 & 1 & 0 \\ 3 & 9 & 1 \\ \end{bmatrix} \]
Which of the following snippets of code would correctly transpose the \(30 \times 20\) matrix \(A\)?
A:
1 2 

B:
1 2 

C::
1 2 

D::
1 2 

Already have an account? Log in here.
Problem Loading...
Note Loading...
Set Loading...