Hướng dẫn how do you use the inverse function in python? - làm thế nào để bạn sử dụng hàm nghịch đảo trong python?

Có thư viện nào có sẵn để có nghịch đảo của một chức năng không? Để cụ thể hơn, được đưa ra một hàm y=f(x) và tên miền, có thư viện nào có thể xuất x=f(y) không? Đáng buồn thay, tôi không thể sử dụng MATLAB/Toán học trong ứng dụng của mình, tìm kiếm thư viện C/Python ..

Hướng dẫn how do you use the inverse function in python? - làm thế nào để bạn sử dụng hàm nghịch đảo trong python?

Đã hỏi ngày 4 tháng 3 năm 2013 lúc 11:32Mar 4, 2013 at 11:32

username_4567username_4567username_4567

4.64511 Huy hiệu vàng54 Huy hiệu bạc91 Huy hiệu Đồng11 gold badges54 silver badges91 bronze badges

5

Tôi hơi muộn, nhưng đối với những độc giả trong tương lai của bài đăng, tôi vừa xuất bản một gói Python làm điều này một cách chính xác. https://pypi.python.org/pypi/pynverse Có một mô tả chi tiết về cách sử dụng nó và cách nó thực hiện trong mô tả!

Đã trả lời ngày 30 tháng 10 năm 2016 lúc 23:51Oct 30, 2016 at 23:51

1

Như đã được đề cập, không phải tất cả các chức năng đều không thể đảo ngược. Trong một số trường hợp áp đặt các ràng buộc bổ sung giúp: suy nghĩ về nghịch đảo của sin(x).

Một khi bạn chắc chắn rằng chức năng của bạn có nghịch đảo duy nhất, hãy giải phương trình f(x) = y. Giải pháp cung cấp cho bạn nghịch đảo, y(x).

Trong Python, hãy tìm người giải quyết phi tuyến từ

from scipy.optimize import minimize

x = np.arange(np.min(y),np.max(y),0.1)

y = np.zeros(x.shape)

def diff(x,a):
    yt = function(x)
    return (yt - a )**2

for idx,x_value in enumerate(x):
    res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
    y[idx] = res.x[0]

fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')

plt.plot(x,y)

plt.title(r'$f^{-1}(x)$')
plt.xlabel('x')
plt.ylabel('y')

plt.savefig("function_inverse.png", bbox_inches='tight')

plt.show()
0.

Đã trả lời ngày 4 tháng 3 năm 2013 lúc 11:54Mar 4, 2013 at 11:54

ev-brev-brev-br

23.9k9 Huy hiệu vàng61 Huy hiệu bạc76 Huy hiệu Đồng9 gold badges61 silver badges76 bronze badges


Làm thế nào để bạn viết một chức năng nghịch đảo trong Python?

Đảo ngược () trong Python. Numpy. Hàm đảo ngược () được sử dụng để tính toán đảo ngược bit khôn ngoan của phần tử mảng. Nó tính toán bit khôn ngoan không phải của biểu diễn nhị phân cơ bản của các số nguyên trong các mảng đầu vào.

Làm thế nào để bạn nghịch đảo một chức năng?

Làm thế nào để bạn tìm thấy nghịch đảo của một hàm? Để tìm nghịch đảo của một hàm, hãy viết hàm y làm hàm của x i.e. y = f (x) và sau đó giải x là hàm của y. How to numerically compute the inverse function in python using scipy ?

Làm thế nào để bạn làm tội lỗi 1 trong Python?

Các sin nghịch đảo còn được gọi là asin hoặc sin^{-1}. Để tìm sin nghịch đảo lượng giác, hãy sử dụng phương pháp numpy.arcsin () trong python numpy. Phương thức trả về sin của mỗi phần tử của tham số 1.

Một ví dụ nghịch đảo là gì? How to numerically compute the inverse function in python using scipy ?

Các hoạt động nghịch đảo là các hoạt động ngược lại mà hoàn tác lẫn nhau. Ví dụ: 5 ✕ 2 = 10 và 10 2 = 5 là các hoạt động nghịch đảo.

  • Ví dụ về cách tính toán hàm nghịch đảo trong Python bằng SCIPY:
  • Xác định một chức năng đơn giản

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọcfunction is used to Compute the bit-wise Inversion of an array element-wise. It computes the bit-wise NOT of the underlying binary representation of the integers in the input arrays.

    Bàn luận

    hàm numpy.invert () được sử dụng để tính toán đảo ngược bit khôn ngoan của một phần tử mảng. Nó tính toán bit khôn ngoan không phải của biểu diễn nhị phân cơ bản của các số nguyên trong các mảng đầu vào. numpy.invert(x, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None, ufunc ‘invert’)

    Đối với các đầu vào số nguyên đã ký, hai phần bổ sung được trả về. Trong một hệ thống bổ sung hai con số âm được thể hiện bằng hai phần bổ sung của giá trị tuyệt đối.
    x : [array_like] Input array.
    out : [ndarray, optional] A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned.
    **kwargs : Allows you to pass keyword variable length of argument to a function. It is used when we want to handle named argument in a function.
    where : [array_like, optional] True value means to calculate the universal functions(ufunc) at that position, False value means to leave the value in the output alone.

    Cú pháp: numpy.invert (x, /, out = none, *, where = true, casting = hồi more_kind [ndarray or scalar] Result. This is a scalar if x is scalar.

    Tham số: x: [mảng_like] mảng đầu vào.out: [ndarray, tùy chọn] một vị trí mà kết quả được lưu trữ. Nếu được cung cấp, nó phải có một hình dạng mà các đầu vào phát sóng. Nếu không được cung cấp hoặc không có, một mảng mới được phân bổ được trả về. ** KWARGS: Cho phép bạn chuyển độ dài biến từ khóa của đối số cho một hàm. Nó được sử dụng khi chúng ta muốn xử lý đối số được đặt tên trong một hàm. Ở đâu đó: [Array_like, Tùy chọn] Giá trị thực có nghĩa là tính toán các hàm phổ quát (UFUNC) tại vị trí đó, giá trị sai có nghĩa là để lại giá trị trong đầu ra.

    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    1
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    2

    Input  number :  10
    inversion of 10 :  -11
    
    9
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    4
    Input array :  [2, 0, 25]
    Output array after inversion:  [ -3  -1 -26]
    
    1y=f(x)4
    Input array :  [2, 0, 25]
    Output array after inversion:  [ -3  -1 -26]
    
    3y=f(x)6
    Input array :  [2, 0, 25]
    Output array after inversion:  [ -3  -1 -26]
    
    7

    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    6
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    7
    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    0x=f(y)1

    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    2
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    4
    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    4

    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    6
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    7
    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    7
    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    8

    Đầu ra:

    Input  number :  10
    inversion of 10 :  -11
    

    Làm thế nào để bạn viết một chức năng nghịch đảo trong Python?
    Code #2 :

    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    1
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    2

    Input  number :  10
    inversion of 10 :  -11
    
    9
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    4
    Input array :  [2, 0, 25]
    Output array after inversion:  [ -3  -1 -26]
    
    1y=f(x)4
    Input array :  [2, 0, 25]
    Output array after inversion:  [ -3  -1 -26]
    
    3y=f(x)6
    Input array :  [2, 0, 25]
    Output array after inversion:  [ -3  -1 -26]
    
    7

    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    6
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    7
    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    0x=f(y)1

    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    2
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    4
    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    4

    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    6
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    7
    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    7
    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    8

    Đầu ra:

    Input array :  [2, 0, 25]
    Output array after inversion:  [ -3  -1 -26]
    

    & nbsp; mã số 3:
    Code #3 :

    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    1
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    2

    Input  number :  10
    inversion of 10 :  -11
    
    9
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    4
    Input array :  [2, 0, 25]
    Output array after inversion:  [ -3  -1 -26]
    
    1y=f(x)4
    Input array :  [2, 0, 25]
    Output array after inversion:  [ -3  -1 -26]
    
    3y=f(x)6
    Input array :  [2, 0, 25]
    Output array after inversion:  [ -3  -1 -26]
    
    7

    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    6
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    7
    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    0x=f(y)1

    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    2
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    4
    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    4

    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    6
    from scipy.optimize import minimize
    
    x = np.arange(np.min(y),np.max(y),0.1)
    
    y = np.zeros(x.shape)
    
    def diff(x,a):
        yt = function(x)
        return (yt - a )**2
    
    for idx,x_value in enumerate(x):
        res = minimize(diff, 1.0, args=(x_value), method='Nelder-Mead', tol=1e-6)
        y[idx] = res.x[0]
    
    fig = figure(num=None, figsize=(12, 10), dpi=80, facecolor='w', edgecolor='k')
    
    plt.plot(x,y)
    
    plt.title(r'$f^{-1}(x)$')
    plt.xlabel('x')
    plt.ylabel('y')
    
    plt.savefig("function_inverse.png", bbox_inches='tight')
    
    plt.show()
    
    7
    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    7
    Input array :  [True, False]
    Output array after inversion:  [False  True]
    
    8

    Đầu ra:

    Input array :  [True, False]
    Output array after inversion:  [False  True]
    

    Làm thế nào để bạn viết một chức năng nghịch đảo trong Python?

    Đảo ngược () trong Python.Numpy.Hàm đảo ngược () được sử dụng để tính toán đảo ngược bit khôn ngoan của phần tử mảng.Nó tính toán bit khôn ngoan không phải của biểu diễn nhị phân cơ bản của các số nguyên trong các mảng đầu vào. in Python. numpy. invert() function is used to Compute the bit-wise Inversion of an array element-wise. It computes the bit-wise NOT of the underlying binary representation of the integers in the input arrays.

    Làm thế nào để bạn nghịch đảo một chức năng?

    Làm thế nào để bạn tìm thấy nghịch đảo của một hàm?Để tìm nghịch đảo của một hàm, hãy viết hàm y làm hàm của x i.e. y = f (x) và sau đó giải x là hàm của y.write the function y as a function of x i.e. y = f(x) and then solve for x as a function of y.

    Làm thế nào để bạn làm tội lỗi 1 trong Python?

    Các sin nghịch đảo còn được gọi là asin hoặc sin^{-1}.Để tìm sin nghịch đảo lượng giác, hãy sử dụng phương pháp numpy.arcsin () trong python numpy.Phương thức trả về sin của mỗi phần tử của tham số 1.use the numpy. arcsin() method in Python Numpy. The method returns the sine of each element of the 1st parameter x.

    Một ví dụ nghịch đảo là gì?

    Các hoạt động nghịch đảo là các hoạt động ngược lại mà hoàn tác lẫn nhau.Ví dụ: 5 ✕ 2 = 10 và 10 2 = 5 là các hoạt động nghịch đảo.5 ✕ 2 = 10 and 10 ÷ 2 = 5 are inverse operations.