1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Whitepunk [10]
3 years ago
9

sparse(compact) Description: A sparse matrix is a 2D matrix that has many zeros. Assume that for storage efficiency someone has

converted a sparse matrix into a compact 2D matrix with dimensions Nx3 where N is the number of non-zero items in the original sparse matrix. In each row of compact, the first column holds the value of a non-zero item of the sparse matrix, the second column holds the row that this item resides in the sparse matrix, and the third column holds the column that this item resides in the sparse matrix. Write a function that given a compact matrix it returns the original sparse matrix. Assume the last row and the last column of the sparse matrix contain at least one non-zero item. Parameters: compact (list of list of int). Return value: a sparse list of list of int Example: sparse([[3,1,2],[4,5,3]]) → [ [0,0,0,0], [0,0,3,0], [0,0,0,0], [0,0,0,0], [0,0,0,0],

Computers and Technology
1 answer:
barxatty [35]3 years ago
8 0

Answer:

Function sparse code is

def sparse(a):

rl = []

cl = []

for i in range(0,len(a)):

rl.append(a[i][1])

cl.append(a[i][2])

r = max(rl)

c = max(cl)

s = []

k = 0

for i in range(0,r+1):

s.append([])

for j in range(0,c+1):

if (i==a[k][1]) & (j == a[k][2]):

s[i].append(a[k][0])

k = k+1

else:

s[i].append(0)

return s

def main():

k = sparse([[3,1,2],[4,5,3]])

print(k)

if __name__ == '__main__':

main()

Explanation:

Please see attachment for output

You might be interested in
What is point mode in excel 2013?
gtnhenbr [62]
I believe it means bullet points as in a form of typing
6 0
3 years ago
Readable code includes the use of
Kobotan [32]

Answer:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBbbbbbbbbbbbbbbbbbbbbbbbbBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB

Explanation:

7 0
2 years ago
Read 2 more answers
What is true about computer files of financial records?
Andrews [41]
Seems like you have forgotten to attach options to choose. But there are some comon statements for such type of tasks and I can recommend you to use this one : finance records should never be kept in computer files. This one is definitely <span> true about computer files of financial records.</span>Next time be more careful.
7 0
3 years ago
Read 2 more answers
Most mobile devices include, among other features, ______ functionality.
AfilCa [17]
PIM would be the answer. Hope this helps. :)
4 0
3 years ago
Simplify to obtain a sum of products: (A+B)(C+B)(D?+B)(ACD?+E)
lilavasa [31]

Answer:

(ACD'+BE)

Explanation:

(A+B)(C+B)(D'+B)(ACD'+E)

Product of (A+B)(C+B)

(A+B)(C+B)=AC+AB+BC+B^2 = AC+B(A+C+B)=AC+B

Product of (D'+B)(ACD'+E) with AC+B

(AC+B)(D'+B)(ACD'+E)

(AC+B)(D'+B)=ACD' + ACB +BD +B = ACD'+B(AC+D+1)=ACD'+B

Then we get:

(ACD'+B)(ACD'+E) = ACD'+ACD'E+ACD'B+BE

ACD'(1+E+B)+BE =ACD'+BE

7 0
3 years ago
Other questions:
  • A portable electronic device that can be used in an emergency to stop someone’s heart from going out of rhythm is called a/an
    6·2 answers
  • What is the magnitude of the largest positive value you can place in a bool? a char? an int? a float? a double??
    8·1 answer
  • Which act requires financial institutions to ensure the security and confidentiality of customer data and mandates that data mus
    8·1 answer
  • In 3–5 sentences, describe how good e-mail work habits increase workplace efficiency and productivity.
    8·1 answer
  • Why is it difficult to detect a Trojan horse?
    13·2 answers
  • Please help fast
    5·1 answer
  • Which formula is a simple formula?<br> O =E10/5+1<br> 0 -5+A1*B1<br> O =C3+10-E3<br> 0 =10-(A3-D13)
    9·1 answer
  • Epic is fuzzy-figure8
    7·2 answers
  • Aurelia is designing a user interface for a new game app. Which of the following should she taken into consideration for the use
    7·1 answer
  • Use the function varimp() on the output of train() and save it to an object called imp:_____.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!