Write a NumPy program to compute natural, base 10, and base 2 logarithms for all elements in a given array

  • برمجة بايثون

Write a NumPy program to compute natural, base 10, and base 2 logarithms for all elements in a given array.

الأجوبة

import numpy as np
x = np.array([1, np.e, np.e**2])
print("Original array: ")
print(x)
print("\nNatural log =", np.log(x))
print("Common log =", np.log10(x))
print("Base 2 log =", np.log2(x))

Sample Output:

Original array: 
[1.         2.71828183 7.3890561 ]

Natural log = [0. 1. 2.]
Common log = [0.         0.43429448 0.86858896]
Base 2 log = [0.         1.44269504 2.88539008]
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...