mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
Optimized recursive_bubble_sort (#2410)
* optimized recursive_bubble_sort * Fixed doctest error due whitespace * reduce loop times for optimization * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -15,28 +15,28 @@ import numpy as np
|
||||
|
||||
def softmax(vector):
|
||||
"""
|
||||
Implements the softmax function
|
||||
Implements the softmax function
|
||||
|
||||
Parameters:
|
||||
vector (np.array,list,tuple): A numpy array of shape (1,n)
|
||||
consisting of real values or a similar list,tuple
|
||||
Parameters:
|
||||
vector (np.array,list,tuple): A numpy array of shape (1,n)
|
||||
consisting of real values or a similar list,tuple
|
||||
|
||||
|
||||
Returns:
|
||||
softmax_vec (np.array): The input numpy array after applying
|
||||
softmax.
|
||||
Returns:
|
||||
softmax_vec (np.array): The input numpy array after applying
|
||||
softmax.
|
||||
|
||||
The softmax vector adds up to one. We need to ceil to mitigate for
|
||||
precision
|
||||
>>> np.ceil(np.sum(softmax([1,2,3,4])))
|
||||
1.0
|
||||
The softmax vector adds up to one. We need to ceil to mitigate for
|
||||
precision
|
||||
>>> np.ceil(np.sum(softmax([1,2,3,4])))
|
||||
1.0
|
||||
|
||||
>>> vec = np.array([5,5])
|
||||
>>> softmax(vec)
|
||||
array([0.5, 0.5])
|
||||
>>> vec = np.array([5,5])
|
||||
>>> softmax(vec)
|
||||
array([0.5, 0.5])
|
||||
|
||||
>>> softmax([0])
|
||||
array([1.])
|
||||
>>> softmax([0])
|
||||
array([1.])
|
||||
"""
|
||||
|
||||
# Calculate e^x for each x in your vector where e is Euler's
|
||||
|
Reference in New Issue
Block a user