Question: Write a python code to perform the following tasks: 1. create a numpy matrix a of dimension 5 x 5 with diagnol entries from 0

Write a python code to perform the following tasks:

1. create a numpy matrix a of dimension 5 x 5 with diagnol entries from 0 to 4 using a single line of python

2. multiply (matrix-vector operation) this matric by a numpy array b with entries b[j] = (2^j)+j, j = 0,....,4, such that c = a * b

3. implement the same multiplication with a for loop and check your previous result

4. multiply elementwise the resulting array c by the numpy array d with components d[j] = j + [j*3.1654], j = 0,...,4. Use typecast to implement the operation [ . ]. This is the floor operation which return the integer part of any floating point number.

5. Sum all the components of the resulting array except the last one, using a single line of python code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!