Replace elements with zeros in python assignment expert
Replace Elements with Zeros Show Given a MxN matrix, write a program to replace all elements that do not belong to principal-diagonal & anti-diagonal with Zeros. Principal-diagonal elements are the set of elements of a matrix that lie on the line joining the top left corner to the bottom right corner. Anti-diagonal elements are the set of elements of a matrix that lie on the line joining the bottom left corner to the top right corner.Input The first line of input will contain two space-separated integers, denoting MxN matrix. The next M lines will contain N space-separated integers.Output The output should be MxN matrix by replacing elements that do not belong to principal-diagonal and anti-diagonal with Zeros. Print each row as a space separated integers in a single line.Explanation For example if the M and N are 5 and 5. Read the elements of 5 rows in next 5 lines. If the given elements are
Harry August 23, 2022 Today, we will see how to replace elements with zeros in Python. We will write two programs for that, in the first one, we will see how to replace elements with zeros in a matrix created using lists in Python, and in the second one, we will
use NumPy. Also Read: Author: HarryHello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at Thank you Post navigationCategoriesOur ServicesContact us on WhatsApp at +91-9760648231 for help with your- python project |