From 9cbf3a8c617a0e856110c44855e3385c41fdf90a Mon Sep 17 00:00:00 2001 From: arisdelacruz <115809819+arisdelacruz@users.noreply.github.com> Date: Wed, 18 Dec 2024 00:20:32 +0800 Subject: [PATCH] [Concept Entry] TensorFlow: Math * Create general math ops for TensorFlow * Update math.md * Update content/tensorflow/concepts/math/math.md Co-authored-by: Savi Dahegaonkar <124272050+SaviDahegaonkar@users.noreply.github.com> * Update content/tensorflow/concepts/math/math.md Co-authored-by: Savi Dahegaonkar <124272050+SaviDahegaonkar@users.noreply.github.com> * Update content/tensorflow/concepts/math/math.md Co-authored-by: Savi Dahegaonkar <124272050+SaviDahegaonkar@users.noreply.github.com> * Update content/tensorflow/concepts/math/math.md Co-authored-by: Savi Dahegaonkar <124272050+SaviDahegaonkar@users.noreply.github.com> * Update content/tensorflow/concepts/math/math.md Co-authored-by: Savi Dahegaonkar <124272050+SaviDahegaonkar@users.noreply.github.com> * Update math.md * Update content/tensorflow/concepts/math/math.md * Update content/tensorflow/concepts/math/math.md * Update content/tensorflow/concepts/math/math.md * Update content/tensorflow/concepts/math/math.md * Update content/tensorflow/concepts/math/math.md * Update content/tensorflow/concepts/math/math.md * Update content/tensorflow/concepts/math/math.md * Update content/tensorflow/concepts/math/math.md * Update content/tensorflow/concepts/math/math.md * Update content/tensorflow/concepts/math/math.md * Fix markdownlint issues * Minor changes --------- --- content/tensorflow/concepts/math/math.md | 144 +++++++++++++++++++++++ documentation/catalog-content.md | 81 +++++++------ 2 files changed, 188 insertions(+), 37 deletions(-) create mode 100644 content/tensorflow/concepts/math/math.md diff --git a/content/tensorflow/concepts/math/math.md b/content/tensorflow/concepts/math/math.md new file mode 100644 index 00000000000..9f4823a51e1 --- /dev/null +++ b/content/tensorflow/concepts/math/math.md @@ -0,0 +1,144 @@ +--- +Title: 'Math' +Description: 'Mathematical computations on tensors using TensorFlow.' +Subjects: + - 'AI' + - 'Data Science' +Tags: + - 'Arithmetic' + - 'Arrays' + - 'Deep Learning' + - 'TensorFlow' +CatalogContent: + - 'intro-to-tensorflow' + - 'tensorflow-for-deep-learning' +--- + +In TensorFlow, **math operations** are fundamental for performing various mathematical computations on tensors. Tensors are multi-dimensional arrays that can be manipulated using various operations. + +TensorFlow offers a rich set of mathematical operations under the `tf.math` module. These operations include arithmetic, trigonometric and exponential functions, and more. + +Some of the key mathematical operations available in TensorFlow are listed below. + +## Arithmetic Operations + +TensorFlow provides a wide range of arithmetic operations that can be performed on tensors, including addition, subtraction, multiplication, division, and more. Here are some examples of arithmetic operations in TensorFlow: + +```py +import tensorflow as tf + +a = tf.constant([1, 2, 3]) +b = tf.constant([4, 5, 6]) + +# Arithmetic operations + +tf.math.add(a, b) # Element-wise addition +tf.math.subtract(a, b) # Element-wise subtraction +tf.math.multiply(a, b) # Element-wise multiplication +tf.math.divide(a, b) # Element-wise division +``` + +## Element-wise Operations + +Element-wise operations are operations applied to each element of a tensor individually. These operations include computing each element's power, calculating each element's square root, and returning the absolute value of each component. Here are some examples of element-wise operations in TensorFlow: + +```py +import tensorflow as tf + +a = tf.constant([1, 2, 3], dtype=tf.float32) + +# Element-wise operations + +tf.math.pow(a, 2) # Element-wise power +tf.math.sqrt(a) # Element-wise square root +tf.math.abs(a) # Element-wise absolute value +``` + +## Trigonometric Functions + +TensorFlow supports trigonometric functions such as sine, cosine, tangent, and their inverses, which have domain constraints. These functions are useful for various mathematical computations. Here are some examples of trigonometric functions in TensorFlow: + +```py +import tensorflow as tf + +a = tf.constant([0.0, 1.0, 2.0]) + +# Trigonometric functions + +tf.math.sin(a) # Element-wise sine +tf.math.cos(a) # Element-wise cosine +tf.math.tan(a) # Element-wise tangent +tf.math.asin(a) # Element-wise arcsine +tf.math.acos(a) # Element-wise arccosine +tf.math.atan(a) # Element-wise arctangent +``` + +## Exponential and Logarithmic Functions + +TensorFlow offers functions to compute exponentials and logarithms of tensor elements, widely used in mathematical and scientific computations. Here are some examples of exponential and logarithmic functions in TensorFlow: + +```py +import tensorflow as tf + +a = tf.constant([1.0, 2.0, 3.0]) + +# Exponential and logarithmic functions + +tf.math.exp(a) # Element-wise exponential +tf.math.log(a) # Element-wise natural logarithm +tf.math.log10(a) # Element-wise base-10 logarithm +tf.math.log1p(a) # Element-wise natural logarithm of (1 + x) +``` + +## Reduction Operations + +Reduction operations compute a single result from multiple tensor elements. These operations include sum, mean, maximum, minimum, and more. Here are some examples of reduction operations in TensorFlow: + +```py +import tensorflow as tf + +a = tf.constant([[1, 2, 3], [4, 5, 6]]) + +# Reduction operations + +tf.math.reduce_sum(a) # Sum of all elements +tf.math.reduce_mean(a) # Mean of all elements +tf.math.reduce_max(a) # Maximum value +tf.math.reduce_min(a) # Minimum value +``` + +## Comparison Operations + +TensorFlow supports comparison operations that compare tensor elements and return boolean values based on the comparison results. Here are some examples of comparison operations in TensorFlow: + +```py +import tensorflow as tf + +a = tf.constant([1, 2, 3]) +b = tf.constant([3, 2, 1]) + +# Comparison operations + +tf.math.equal(a, b) # Element-wise equality +tf.math.less(a, b) # Element-wise less than +tf.math.greater(a, b) # Element-wise greater than +tf.math.not_equal(a, b) # Element-wise inequality +``` + +## Special Functions + +TensorFlow offers a variety of special mathematical functions such as `Bessel` functions, `error` functions, and `gamma` functions. These functions are useful for advanced mathematical computations. Here are some examples of special functions in TensorFlow: + +```py +import tensorflow as tf + +a = tf.constant([1.0, 2.0, 3.0]) + +# Special functions + +tf.math.erf(a) # Element-wise error function +tf.math.lgamma(a) # Element-wise natural logarithm of the absolute value of the gamma function of x +tf.math.bessel_i0(a) # Element-wise modified Bessel function of the first kind of order 0 +``` + +By leveraging these mathematical operations, a wide range of computations on tensors can be performed in TensorFlow, making it a powerful tool for scientific computing, machine learning, and deep learning applications. diff --git a/documentation/catalog-content.md b/documentation/catalog-content.md index 44c6da9ba57..955d04c350f 100644 --- a/documentation/catalog-content.md +++ b/documentation/catalog-content.md @@ -9,63 +9,63 @@ These slugs may vary for different topics. Feel free to add suggestions for new slugs to the lists as part of your PR! Be sure to insert them alphabetically. -### C +## C ``` - 'learn-c' - 'paths/computer-science' ``` -### C++ +## C++ ``` - 'learn-c-plus-plus' - 'paths/computer-science' ``` -### Cloud Computing +## Cloud Computing ``` - 'foundations-of-cloud-computing' - 'paths/back-end-engineer-career-path' ``` -### Command Line +## Command Line ``` - 'learn-the-command-line' - 'paths/computer-science' ``` -### CSS +## CSS ``` - 'learn-css' - 'paths/front-end-engineer-career-path' ``` -### Cybersecurity +## Cybersecurity ``` - 'introduction-to-cybersecurity' - 'paths/fundamentals-of-cybersecurity' ``` -### Dart +## Dart ``` - 'learn-dart' - 'paths/computer-science' ``` -### Emojicode +## Emojicode ``` - 'learn-emojicode' - 'paths/computer-science' ``` -### Git +## Git ``` - 'learn-git' @@ -73,7 +73,7 @@ Feel free to add suggestions for new slugs to the lists as part of your PR! Be s - 'paths/computer-science' ``` -### Go +## Go ``` - 'learn-go' @@ -81,77 +81,77 @@ Feel free to add suggestions for new slugs to the lists as part of your PR! Be s - 'paths/computer-science' ``` -### HTML +## HTML ``` - 'learn-html' - 'paths/front-end-engineer-career-path' ``` -### Java +## Java ``` - 'learn-java' - 'paths/computer-science' ``` -### JavaScript +## JavaScript ``` - 'introduction-to-javascript' - 'paths/front-end-engineer-career-path' ``` -### JavaScript:D3 +## JavaScript:D3 ``` - 'learn-d3' - 'paths/data-science' ``` -### Kotlin +## Kotlin ``` - 'learn-kotlin' - 'paths/computer-science' ``` -### Markdown +## Markdown ``` - 'learn-html' - 'paths/front-end-engineer-career-path' ``` -### Open Source +## Open Source ``` - 'introduction-to-open-source' - 'paths/code-foundations' ``` -### PHP +## PHP ``` - 'learn-php' - 'paths/computer-science' ``` -### PowerShell +## PowerShell ``` - 'learn-powershell' - 'paths/computer-science' ``` -### Python +## Python ``` - 'learn-python-3' - 'paths/computer-science' ``` -### Python:Matplotlib +## Python:Matplotlib ``` - 'learn-python-3' @@ -160,7 +160,7 @@ Feel free to add suggestions for new slugs to the lists as part of your PR! Be s - 'paths/data-science-foundations' ``` -### Python:Numpy +## Python:Numpy ``` - 'learn-python-3' @@ -169,7 +169,7 @@ Feel free to add suggestions for new slugs to the lists as part of your PR! Be s - 'paths/data-science-foundations' ``` -### Python:Pandas +## Python:Pandas ``` - 'learn-python-3' @@ -178,7 +178,7 @@ Feel free to add suggestions for new slugs to the lists as part of your PR! Be s - 'paths/data-science-foundations' ``` -### Python:Pillow +## Python:Pillow ``` - 'learn-python-3' @@ -187,7 +187,7 @@ Feel free to add suggestions for new slugs to the lists as part of your PR! Be s - 'paths/data-science-foundations' ``` -### Python:Plotly +## Python:Plotly ``` - 'learn-python-3' @@ -196,7 +196,7 @@ Feel free to add suggestions for new slugs to the lists as part of your PR! Be s - 'paths/data-science-foundations' ``` -### Python:PyTorch +## Python:PyTorch ``` - 'intro-to-py-torch-and-neural-networks' @@ -208,7 +208,7 @@ Feel free to add suggestions for new slugs to the lists as part of your PR! Be s - 'paths/machine-learning' ``` -### Python:Seaborn +## Python:Seaborn ``` - 'learn-python-3' @@ -217,13 +217,20 @@ Feel free to add suggestions for new slugs to the lists as part of your PR! Be s - 'paths/data-science-foundations' ``` -### Python:Sklearn +## Python:Sklearn ``` - 'paths/intermediate-machine-learning-skill-path' ``` -### R +## Python:TensorFlow + +``` +- 'intro-to-tensorflow' +- 'tensorflow-for-deep-learning' +``` + +## R ``` - 'learn-r' @@ -232,14 +239,14 @@ Feel free to add suggestions for new slugs to the lists as part of your PR! Be s - 'paths/computer-science' ``` -### React +## React ``` - 'react-101' - 'paths/front-end-engineer-career-path' ``` -### Ruby +## Ruby ``` - 'learn-rails' @@ -247,14 +254,14 @@ Feel free to add suggestions for new slugs to the lists as part of your PR! Be s - 'paths/full-stack-engineer-career-path' ``` -### Rust +## Rust ``` - 'rust-for-programmers' - 'paths/computer-science' ``` -### SQL +## SQL ``` - 'learn-sql' @@ -263,28 +270,28 @@ Feel free to add suggestions for new slugs to the lists as part of your PR! Be s - 'paths/data-science-foundations' ``` -### Swift +## Swift ``` - 'learn-swift' - 'paths/build-ios-apps-with-swiftui' ``` -### SwiftUI +## SwiftUI ``` - 'learn-swift' - 'paths/build-ios-apps-with-swiftui' ``` -### TypeScript +## TypeScript ``` - 'learn-typescript' - 'paths/full-stack-engineer-career-path' ``` -### UI/UX +## UI/UX ``` - 'intro-to-ui-ux'