Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ft/ai-gradient-descent
Browse files Browse the repository at this point in the history
mamtawardhani authored Dec 18, 2024
2 parents d4dfea6 + 9cbf3a8 commit ea4e9e8
Showing 3 changed files with 335 additions and 37 deletions.
147 changes: 147 additions & 0 deletions content/python/concepts/sql-connectors/terms/sqlite3/sqlite3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
---
Title: 'SQLite3'
Description: 'SQLite3 is a library used to connect to SQLite databases.'
Subjects:
- 'Computer Science'
- 'Data Science'
Tags:
- 'SQLite'
- 'Documentation'
CatalogContent:
- 'learn-python-3'
- 'paths/computer-science'
---

The **`sqlite3`** library is used to connect to SQLite databases and provides functions to interact with them. It can also be used for prototyping while developing an application.

## Syntax

```pseudo
import sqlite3
```

The `sqlite3` library handles the communication with the databases.

## Create a Connection

To work with a database, it first needs to be connected to using the **`.connect()`** function:

```py
import sqlite3

con = sqlite3.connect("mydb_db.db")
```

## Create a Cursor

A cursor is required to execute SQL statements and the **`.cursor()`** function creates one:

```py
curs = connection.cursor()
```

## Create a Table

The **`.execute()`** function can be used to create a table:

```py
curs.execute('''CREATE TABLE persons(
name TEXT,
age INTEGER,
gender TEXT)
''')
```

## Insert a Value Into the Table

To insert values into the table, the SQL statement is executed with the `.execute()` function:

```py
curs.execute('''INSERT INTO persons VALUES(
'Alice', 21, 'female')''')
```

## Insert Multiple Values Into the Table

To insert multiple values into the table, the SQL statement is executed using the **`.executemany()`** function with an array of values:

```py
new_persons = [('Bob', 26, 'male'),
('Charlie', 19, 'male'),
('Daisy', 18, 'female')
]

curs.executemany('''INSERT INTO persons VALUES(?, ?, ?)''', new_persons)
```

## Commit the Transaction

The **`.commit()`** function saves the inserted values to the database permanently:

```py
con.commit()
```

## Check the Inserted Rows

To check all the inserted rows, the **`.fetchall()`** function can be used:

```py
result = cursor.execute("SELECT * FROM persons")

result.fetchall()
```

## Close the Connection

After completing all the transactions, the connection can be closed with **`.close()`**:

```py
connection.close()
```

## Codebyte Example

Here's a codebyte example showing how to connect to an SQLite database, create a table, insert/query data, and close the connection:

```codebyte/python
import sqlite3
# Create a connection to the database
con = sqlite3.connect("mydb_db.db")
# Create a cursor to execute SQL statements
curs = con.cursor()
# Ensure to create a new table
curs.execute('''DROP TABLE IF EXISTS persons''')
# Create a new table
curs.execute('''CREATE TABLE persons(
name TEXT,
age INTEGER,
gender TEXT)
''')
# Insert a value into the table
curs.execute('''INSERT INTO persons VALUES(
'Alice', 21, 'female')''')
# Insert multiple values into the table
new_persons = [('Bob', 26, 'male'),
('Charlie', 19, 'male'),
('Daisy', 18, 'female')
]
curs.executemany('''INSERT INTO persons VALUES(?, ?, ?)''', new_persons)
# Commit the transaction to database
con.commit()
# Check the inserted rows
result = curs.execute("SELECT * FROM persons")
printout = result.fetchall()
print(printout)
# Close the connection
con.close()
```
144 changes: 144 additions & 0 deletions content/tensorflow/concepts/math/math.md
Original file line number Diff line number Diff line change
@@ -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.
81 changes: 44 additions & 37 deletions documentation/catalog-content.md
Original file line number Diff line number Diff line change
@@ -9,149 +9,149 @@ 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'
- 'learn-the-command-line'
- 'paths/computer-science'
```

### Go
## Go

```
- 'learn-go'
- 'paths/back-end-engineer-career-path'
- '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,29 +239,29 @@ 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'
- 'learn-ruby'
- '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'

0 comments on commit ea4e9e8

Please sign in to comment.