Skip to content

Commit

Permalink
Create /autonotebook command for AI generated notebooks (#90)
Browse files Browse the repository at this point in the history
* Initial autonotebook work.

* Working autonotebook.

* Adding first autogenerated notebook example.

* Removing file.

* Adding second autonotebook example.

* Cleaning up code, renaming autonotebook to generate.

* Minor fixes, adding new example notebook.

* Renaming examples subdir.
  • Loading branch information
ellisonbg authored Apr 20, 2023
1 parent e6a78ad commit 629909a
Show file tree
Hide file tree
Showing 6 changed files with 1,563 additions and 1 deletion.
360 changes: 360 additions & 0 deletions examples/generate/Creating Random Arrays with Numpy.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,360 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "c46fd5c5",
"metadata": {},
"source": [
"# Creating Random Arrays with Numpy"
]
},
{
"cell_type": "markdown",
"id": "a2a4149f",
"metadata": {},
"source": [
"## Introduction"
]
},
{
"cell_type": "markdown",
"id": "4b488198",
"metadata": {},
"source": [
"This notebook was created by [Jupyter AI](https://github.com/jupyterlab/jupyter-ai) with the following prompt:\n",
"\n",
"> /generate Create a Jupyter notebook that shows how to create a random array using numpy."
]
},
{
"cell_type": "markdown",
"id": "c6460605",
"metadata": {},
"source": [
"This Jupyter notebook demonstrates how to create a random array using numpy. It covers topics such as importing necessary packages, creating a random array, setting the array size and shape, setting the data type of the array, and generating a random array with specified parameters. Each section includes sample code for creating a random array and printing the results. This notebook is useful for anyone looking to generate random arrays in their data analysis or machine learning projects."
]
},
{
"cell_type": "markdown",
"id": "9cfcc84c",
"metadata": {},
"source": [
"## Creating a random array"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "4c50ec33",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "02a9481d",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"np.random.seed(123)\n",
"random_array = np.random.rand(3, 4)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5ed2a6c8",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Random array:\n",
" [[0.69646919 0.28613933 0.22685145 0.55131477]\n",
" [0.71946897 0.42310646 0.9807642 0.68482974]\n",
" [0.4809319 0.39211752 0.34317802 0.72904971]]\n"
]
}
],
"source": [
"print(\"Random array:\\n\", random_array)"
]
},
{
"cell_type": "markdown",
"id": "2e9d4225",
"metadata": {},
"source": [
"## Setting the array size and shape"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "15bfe3cb",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "2aedfee5",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Set the size and shape of the random array\n",
"array_size = (3, 4) # number of rows and columns"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "6dc9a89a",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Create the random array using the specified size and shape\n",
"random_array = np.random.rand(*array_size) # *array_size unpacks the tuple"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "7b4b2ae5",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Random array:\n",
" [[0.43857224 0.0596779 0.39804426 0.73799541]\n",
" [0.18249173 0.17545176 0.53155137 0.53182759]\n",
" [0.63440096 0.84943179 0.72445532 0.61102351]]\n"
]
}
],
"source": [
"# Print the random array\n",
"print(\"Random array:\\n\", random_array)"
]
},
{
"cell_type": "markdown",
"id": "863dd179",
"metadata": {},
"source": [
"## Setting the data type of the array"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "fed55a87",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "d2fa2a10",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Set the data type of the random array to be created\n",
"dtype = np.int32"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "9c462fdb",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Set the size and shape of the random array\n",
"array_size = (3, 4) # number of rows and columns"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "ddcf206e",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Create the random array using the specified size, shape, and data type\n",
"random_array = np.random.randint(low=0, high=10, size=array_size, dtype=dtype)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "fcc3d78c",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Random array:\n",
" [[4 6 1 5]\n",
" [6 2 1 8]\n",
" [3 5 0 2]]\n"
]
}
],
"source": [
"# Print the random array\n",
"print(\"Random array:\\n\", random_array)"
]
},
{
"cell_type": "markdown",
"id": "f1c81186",
"metadata": {},
"source": [
"## Generating a random array with specified parameters"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "b0526789",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "9ebd784c",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"array_size = (5, 7) \n",
"min_val = -10\n",
"max_val = 10"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "56567059",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"def create_random_array(size, low, high):\n",
" return np.random.randint(low=low, high=high, size=size)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "57c8282d",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"random_array = create_random_array(array_size, min_val, max_val)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "a2c9d87f",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Random array:\n",
" [[ 0 3 8 -6 5 1 2]\n",
" [-4 3 9 6 -4 4 -3]\n",
" [ 1 -3 -9 1 -5 8 7]\n",
" [ 2 8 7 -9 9 2 -1]\n",
" [ 6 7 -7 -7 1 -3 -1]]\n"
]
}
],
"source": [
"print(\"Random array:\\n\", random_array)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0abd2b89-c2e1-4083-9d4a-29da5a2096c3",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 629909a

Please sign in to comment.