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]
2 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]2 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
Which of the following represents inbound logistics for a bookstore
sergiy2304 [10]
What are the answer choices ????

4 0
2 years ago
(1) Prompt the user to enter two words and a number, storing each into separate variables. Then, output those three values on a
denpristay [2]

Answer:Prompt the user to enter two words and a number, storing each into separate variables. Then, output those three values on a single line separated by a space. (Submit for 1 point) Ex: If the input is: yellow Daisy 6 the output after the prompts is: You entered: yellow Daisy 6 Note: User input is not part of the program output. (2) Output two passwords using a combination of the user input. Format the passwords as shown below. (Submit for 2 points, so 3 points total). Ex: If the input is: yellow Daisy 6 the output after the prompts is: You entered: yellow Daisy 6 First password: yellow_Daisy Second password: 6yellow6 (3) Output the length of each password (the number of characters in the strings). (Submit for 2 points, so 5 points total). Ex: If the input is: yellow Daisy 6 the output after the prompts is: You entered: yellow Daisy 6 First password: yellow_Daisy Second password: 6yellow6 Number of characters in yellow_Daisy: 12 Number of characters in 6yellow6: 8

I have tried several different ways of doing this, but I keep getting an error on line 6

Explanation:

7 0
2 years ago
What is the cpu used for
Dahasolnce [82]

Answer:

A central processing unit (CPU), also called a central processor, main processor or just processor, is the electronic circuitry that executes instructions comprising a computer program. The CPU performs basic arithmetic, logic, controlling, and input/output (I/O) operations specified by the instructions in the program.

4 0
3 years ago
Write smallest to largest: Byte, bit, MB, PB, GB, nibble
OlgaM077 [116]

Answer:

  1. bit
  2. nibble
  3. byte
  4. MB
  5. GB
  6. PB

Explanation:

this is it!!!

3 0
3 years ago
Read 2 more answers
X = 1 if (A = 1 OR B = 1) OR (A = 0 AND B = 1
Gnoma [55]

Answer:

For question a, it simplifies.  If you re-express it in boolean algebra, you get:

(a + b) + (!a + b)

= a + !a + b

= b

So you can simplify that circuit to just:

x = 1 if b = 1

(edit: or rather, x = b)

For question b, let's try it:

(!a!b)(!b + c)

= !a!b + !a!bc

= !a!b(1 + c)

= !a!b

So that one can be simplified to

a = 0 and b = 0

I have no good means of drawing them here, but hopefully the simplification helped!

4 0
3 years ago
Other questions:
  • A deleted file or folder is not permanently deleted from a computer until which event occurs? The computer is restarted. The Rec
    13·2 answers
  • The manager of a sports club has data about the club members' ages in a workbook. He wants to find which age is most common. Whi
    13·2 answers
  • What tasks does google do?
    5·1 answer
  • A server that provides data transfer and storage space at remote locations is called a
    7·1 answer
  • If str 1 and str2 are both Strings, which of the following expressions will correctly
    13·1 answer
  • Describe how one can change row and height
    6·1 answer
  • What can a scientist do if he repeats and experiment and gets diffrent results?
    5·1 answer
  • What is the difference between KE an PE
    8·1 answer
  • _________ can be used to provide access control, confidentiality, data origin authentication, connectionless integrity, rejectio
    12·1 answer
  • Can i eat chicken and you shut
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!