Предмет: Информатика, автор: andrew001122

СРОЧНО ДАМ 50 БАЛЛОВ пайтон
1. З використанням можливостей NumPy побудуйте векторний калькулятор. Аргументами повинні бути або числа, або вектори.


Розмірність векторів може бути змінною, вводіть її перед виконанням операцій.


2. Додайте калькулятору можливість будувати графік функції за допомогою matplotlib.

Ответы

Автор ответа: 4asnykgamer
2

Ответ: Ось так?

import numpy as np

import matplotlib.pyplot as plt

def vector_calc():

   print("Vector calculator")

   print("Enter the size of the vector")

   size = int(input())

   print("Enter the vector")

   vector = np.array([float(input()) for i in range(size)])

   print("Enter the operation")

   operation = input()

   if operation == "+":

       print("Enter the second vector")

       vector2 = np.array([float(input()) for i in range(size)])

       print(vector + vector2)

   elif operation == "-":

       print("Enter the second vector")

       vector2 = np.array([float(input()) for i in range(size)])

       print(vector - vector2)

   elif operation == "*":

       print("Enter the second vector")

       vector2 = np.array([float(input()) for i in range(size)])

       print(vector * vector2)

   elif operation == "/":

       print("Enter the second vector")

       vector2 = np.array([float(input()) for i in range(size)])

       print(vector / vector2)

   elif operation == "scalar":

       print("Enter the second vector")

       vector2 = np.array([float(input()) for i in range(size)])

       print(np.dot(vector, vector2))

   elif operation == "norm":

       print(np.linalg.norm(vector))

   elif operation == "plot":

       print("Enter the function")

       func = input()

       x = np.linspace(-10, 10, 1000)

       y = eval(func)

       plt.plot(x, y)

       plt.show()

   else:

       print("Invalid operation")

if __name__ == "__main__":

   vector_calc()


andrew001122: боже, спасибо огромное
Похожие вопросы