Add Euler Mascheroni Constant to Each Element of a NumPy Array

In this tutorial, we will see how to add the Euler-Mascheroni Constant to Each Element of a Numpy Array in Python. Numpy is a Python library that provides multidimensional, large arrays and matrices with mathematical functions to use with the arrays & the Euler-Mascheroni Constant is a mathematical constant, that represents the limit of the difference between harmonic series and natural logarithms. Symbol γ (gamma) is used to denote this. The approximate value of the Euler-Mascheroni Constant is equal to 0.57721566.

Requirements:

  • Numpy

To get started, you need to install Numpy if not already present on your system. You can install it using PIP which is a package installer for Python programming language. You can install it on your system by opening Command Prompt if you are using Windows or Terminal if you are using a Linux or Mac operating system and running the following code.

pip install numpy

You can check this one: NumPy installation and array creation

Python Code:

In this code, I used np.euler_gamma which is the Euler-Mascheroni Constant value from Numpy and added to the array.

import numpy as np

# Create a NumPy array
arr = np.array([10, 20, 30, 40, 50])

# Add the Euler-Mascheroni constant to each element
arr = arr + np.euler_gamma

# Print the updated array
print(arr)

Output:

[10.57721566 20.57721566 30.57721566 40.57721566 50.57721566]

 

Leave a Reply

Your email address will not be published. Required fields are marked *