Skip to content

Instantly share code, notes, and snippets.

@PhilipMay
Created July 10, 2020 19:17
Show Gist options
  • Save PhilipMay/90354d112e3da69c38c7211bbdec9bde to your computer and use it in GitHub Desktop.
Save PhilipMay/90354d112e3da69c38c7211bbdec9bde to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "stack_arrays_in_list.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "code",
"metadata": {
"id": "yMzlFiIEJlpc",
"colab_type": "code",
"colab": {}
},
"source": [
"import numpy as np"
],
"execution_count": 1,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "F_mtmyzCJqeB",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "bfcdd0f1-3a5d-4737-9626-ad086baa4dc2"
},
"source": [
"my_list = []\n",
"a = np.array([1, 2, 3])\n",
"my_list.append(a)\n",
"b = np.array([2, 3, 4])\n",
"my_list.append(b)\n",
"print(my_list)"
],
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"text": [
"[array([1, 2, 3]), array([2, 3, 4])]\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "nkDEkLDyJiw8",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 53
},
"outputId": "b1c53d4a-4555-4c5f-b384-7efc0cc5d246"
},
"source": [
"array_stack = np.stack((a, b))\n",
"print(array_stack)"
],
"execution_count": 4,
"outputs": [
{
"output_type": "stream",
"text": [
"[[1 2 3]\n",
" [2 3 4]]\n"
],
"name": "stdout"
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment