Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python Programming In Python, write and test a procedure vec select using a comprehension for the following computational problem: input: a list veclist of

In Python Programming

In Python, write and test a procedure vec select using a comprehension for the following computational problem:

input: a list veclist of vectors over the same domain, and an element k of the domain

output: the sublist of veclist consisting of the vectors v in veclist where v[k] is zero

Write and test a procedure vec sum using the built-in procedure sum() for the following:

input: a list veclist of vectors, and a set D that is the common domain of these vectors

output: the vector sum of the vectors in veclist.

Your procedure must work even if veclist has length 0.

Hint: Recall from the Python Lab that sum() optionally takes a second argument, which is the element to start the sum with. This can be a vector.

Disclaimer: The Vec class is defined in such a way that, for a vector v, the expression 0 + v evaluates to v. This was done precisely so that sum([v1,v2,... vk]) will correctly evaluate to the sum of the vectors when the number of vectors is nonzero. However, this wont work when the number of vectors is zero.

Put your procedures together to obtain a procedure vec select sum for the following:

input: a set D, a list veclist of vectors with domain D, and an element k of the domain

output: the sum of all vectors v in veclist where v[k] is zero

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started