Created
April 21, 2023 19:00
-
-
Save jreadey/c7628b6fa4636958e6e59741626f94e0 to your computer and use it in GitHub Desktop.
linspace example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "6f42f9f3-53aa-43f7-a193-71b9cb098cb6", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import h5pyd as h5py" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "0a3b76cc-f6ff-422d-a636-d783f86b963f", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"N_ARRAY = 255" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"id": "3778f181-9920-4458-8bcd-5260227fb79b", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"arr = np.linspace(0,100,N_ARRAY)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"id": "67b8ecc3-90a6-4f57-afb1-5eaa6c912c37", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(255,)" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"arr.shape" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"id": "368f6b03-7a00-4d2b-9357-da4b36d4332c", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([0. , 0.39370079, 0.78740157, 1.18110236, 1.57480315,\n", | |
" 1.96850394, 2.36220472, 2.75590551, 3.1496063 , 3.54330709,\n", | |
" 3.93700787, 4.33070866])" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"arr[0:12]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"id": "0d296070-4cd4-4597-b65d-5b6ef0de281f", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"dtype('float64')" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"arr.dtype" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"id": "16ad2201-cbd6-4556-aa78-0708477abf57", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"f = h5py.File(\"/home/jreadey/linspace.h5\", \"w\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"id": "d132fe5d-e849-4047-b2d9-64818378f663", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"dset=f.create_dataset(\"dset255\",data=np.linspace(0,100,N_ARRAY), dtype=np.float32)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"id": "08c1014b-e145-4311-8e2a-bb963bd04fe4", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<HDF5 dataset \"dset255\": shape (255,), type \"<f4\">" | |
] | |
}, | |
"execution_count": 13, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"dset" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"id": "8ad24a6c-f588-4be4-8ea0-c395d35925e6", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([0. , 0.39370078, 0.78740156, 1.1811024 , 1.5748031 ,\n", | |
" 1.968504 , 2.3622048 , 2.7559056 , 3.1496062 , 3.543307 ],\n", | |
" dtype=float32)" | |
] | |
}, | |
"execution_count": 14, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"dset[0:10]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"id": "873dd092-bc37-4f11-baf0-697868eab560", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"N_ARRAY=260" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"id": "5e51a249-1495-4b90-a68e-ca1175db1e90", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"dset=f.create_dataset(\"dset260\",data=np.linspace(0,100,N_ARRAY), dtype=np.float32)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 18, | |
"id": "20e9dc7f-1510-4139-93ef-92a8ce0e9f08", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([0. , 0.38610038, 0.77220076, 1.1583011 , 1.5444015 ,\n", | |
" 1.9305019 , 2.3166022 , 2.7027028 , 3.088803 , 3.4749036 ],\n", | |
" dtype=float32)" | |
] | |
}, | |
"execution_count": 18, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"dset[0:10]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"id": "74528864-fe2f-4d92-9cd7-3c7856d1bfda", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"N_ARRAY=10000" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"id": "61e8bd09-b292-46ff-9b83-e6e41de2ed68", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"dset=f.create_dataset(\"dset10K\",data=np.linspace(0,100,N_ARRAY), dtype=np.float32)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 21, | |
"id": "957b4d5e-e44d-4148-a0b1-5a6df536c139", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([0. , 0.010001, 0.020002, 0.030003, 0.040004, 0.050005,\n", | |
" 0.060006, 0.070007, 0.080008, 0.090009], dtype=float32)" | |
] | |
}, | |
"execution_count": 21, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"dset[0:10]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "34df6e83-2634-4924-a148-649434747dba", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"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.9.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment