do you mean to do something like this using pytorch?
Problem 1:

Screenshot (941)1814×645 20.8 KB


Screenshot (942)1839×570 17.7 KB

Problem 2:

Screenshot (945)1802×730 30.5 KB


Screenshot (946)1851×304 13.8 KB