{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "a7539c22", "metadata": { "_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19", "_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5", "execution": { "iopub.execute_input": "2024-11-17T05:58:54.410649Z", "iopub.status.busy": "2024-11-17T05:58:54.410173Z", "iopub.status.idle": "2024-11-17T05:58:55.495726Z", "shell.execute_reply": "2024-11-17T05:58:55.494342Z" }, "papermill": { "duration": 1.093188, "end_time": "2024-11-17T05:58:55.498784", "exception": false, "start_time": "2024-11-17T05:58:54.405596", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "# This Python 3 environment comes with many helpful analytics libraries installed\n", "# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n", "# For example, here's several helpful packages to load\n", "\n", "import numpy as np # linear algebra\n", "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n", "\n", "# Input data files are available in the read-only \"../input/\" directory\n", "# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n", "\n", "import os\n", "for dirname, _, filenames in os.walk('/kaggle/input'):\n", " for filename in filenames:\n", " print(os.path.join(dirname, filename))\n", "\n", "# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n", "# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session" ] }, { "cell_type": "code", "execution_count": 2, "id": "ad0cc7db", "metadata": { "execution": { "iopub.execute_input": "2024-11-17T05:58:55.505703Z", "iopub.status.busy": "2024-11-17T05:58:55.505111Z", "iopub.status.idle": "2024-11-17T05:58:56.224081Z", "shell.execute_reply": "2024-11-17T05:58:56.222818Z" }, "papermill": { "duration": 0.725574, "end_time": "2024-11-17T05:58:56.226902", "exception": false, "start_time": "2024-11-17T05:58:55.501328", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Import necessary libraries\n", "import numpy as np\n", "import plotly.graph_objects as go\n", "import logging\n", "import random\n", "\n", "# Setup logging\n", "logging.basicConfig(level=logging.INFO, format=\"%(asctime)s - %(message)s\")\n", "logger = logging.getLogger()\n", "\n", "# Step 1: Initialize the Boolean Matrix (Cube)\n", "def create_rgb_cube(size=20):\n", " \"\"\"\n", " Create a 3D Boolean matrix to represent the RGB cube.\n", " Each cell corresponds to an RGB combination.\n", " \"\"\"\n", " logger.info(f\"Initializing RGB cube of size {size}x{size}x{size}.\")\n", " return np.zeros((size, size, size), dtype=bool)\n", "\n", "# Step 2: Activate random cells for testing\n", "def activate_random_cells(cube, num_cells=5000):\n", " \"\"\"\n", " Randomly activate a specified number of cells in the cube.\n", " \"\"\"\n", " logger.info(f\"Activating {num_cells} random cells.\")\n", " size = cube.shape[0]\n", " for _ in range(num_cells):\n", " x, y, z = random.randint(0, size - 1), random.randint(0, size - 1), random.randint(0, size - 1)\n", " cube[x, y, z] = True\n", " logger.debug(f\"Activated cell at ({x}, {y}, {z}).\")\n", "\n", "# Step 3: Visualize the Cube\n", "def visualize_rgb_cube(cube):\n", " \"\"\"\n", " Visualize the RGB cube using Plotly.\n", " \"\"\"\n", " logger.info(\"Preparing RGB cube visualization.\")\n", " \n", " # Extract active cell coordinates\n", " x, y, z = np.where(cube)\n", " size = cube.shape[0]\n", " \n", " # Map coordinates to RGB colors\n", " colors = [f\"rgb({int(255 * xi / size)}, {int(255 * yi / size)}, {int(255 * zi / size)})\"\n", " for xi, yi, zi in zip(x, y, z)]\n", " \n", " # Create scatter plot\n", " fig = go.Figure(data=[go.Scatter3d(\n", " x=x, y=y, z=z,\n", " mode='markers',\n", " marker=dict(size=5, color=colors, opacity=0.8),\n", " )])\n", " fig.update_layout(\n", " title=\"3D RGB Cube Visualization\",\n", " scene=dict(\n", " xaxis_title=\"Red Intensity\",\n", " yaxis_title=\"Green Intensity\",\n", " zaxis_title=\"Blue Intensity\",\n", " )\n", " )\n", " fig.show()\n", "\n", "# Step 4: Update Cube with State Changes\n", "def update_cube_state(cube, x, y, z, state=True):\n", " \"\"\"\n", " Update the state of a specific cell in the cube.\n", " \"\"\"\n", " try:\n", " cube[x, y, z] = state\n", " logger.info(f\"Cell at ({x}, {y}, {z}) set to {'Active' if state else 'Inactive'}.\")\n", " except IndexError as e:\n", " logger.error(f\"Failed to update cell at ({x}, {y}, {z}): {e}\")\n", "\n", "# Step 5: Debugging Example\n", "def debug_matrix(cube):\n", " \"\"\"\n", " Print a summary of the matrix for debugging.\n", " \"\"\"\n", " active_cells = np.sum(cube)\n", " logger.info(f\"Cube Summary: {active_cells} active cells.\")\n", " return active_cells\n", "\n", "# Main Workflow\n", "if __name__ == \"__main__\":\n", " # Initialize the cube\n", " size = 100\n", " rgb_cube = create_rgb_cube(size)\n", "\n", " # Activate random cells\n", " activate_random_cells(rgb_cube, num_cells=1000)\n", "\n", " # Debug and log the state of the matrix\n", " debug_matrix(rgb_cube)\n", "\n", " # Update specific cells\n", " update_cube_state(rgb_cube, 5, 10, 15, state=True)\n", " update_cube_state(rgb_cube, 10, 10, 10, state=False)\n", "\n", " # Visualize the RGB cube\n", " visualize_rgb_cube(rgb_cube)" ] } ], "metadata": { "kaggle": { "accelerator": "none", "dataSources": [], "dockerImageVersionId": 30786, "isGpuEnabled": false, "isInternetEnabled": true, "language": "python", "sourceType": "notebook" }, "kernelspec": { "display_name": "Python 3", "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.10.14" }, "papermill": { "default_parameters": {}, "duration": 5.683453, "end_time": "2024-11-17T05:58:56.752401", "environment_variables": {}, "exception": null, "input_path": "__notebook__.ipynb", "output_path": "__notebook__.ipynb", "parameters": {}, "start_time": "2024-11-17T05:58:51.068948", "version": "2.6.0" } }, "nbformat": 4, "nbformat_minor": 5 }