{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "

What is xnd?

\n", "\n", "xnd is a module that implements a container type for mapping all python values relevant for scientific computing directly to memory.\n", "xnd has a superset of features for typed memory found in similar libraries like numpy and apache arrow. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from xnd import xnd\n", "import numpy as np\n", "import sys" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Python 3.7.3 | packaged by conda-forge | (default, Mar 27 2019, 23:01:00) \n", "[GCC 7.3.0]\n" ] } ], "source": [ "print('Python %s' % sys.version)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Xnd container creation routines" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating xnd container from Python data types\n", "\n", "- xnd supports type inference. This allows the user to create xnd container from Python data types. " ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "xnd([1, 2, 3, 4, 5], type='5 * int64')" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xnd([1, 2, 3, 4, 5]) # xnd" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1, 2, 3, 4, 5])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.array([1, 2, 3, 4, 5]) # numpy " ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "xnd([[1.0, 1.5], [-1.5, 1.0]], type='2 * 2 * float64')" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xnd([[1., 1.5], [-1.5, 1.]]) # xnd" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 1. , 1.5],\n", " [-1.5, 1. ]])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.array([[1, 1.5], [-1.5, 1]]) # numpy " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "You can see some differences with numpy at this level already, such as the array dimensionality being included in the type." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- The default string is variable-length in xnd. In numpy, you either choose a maximum size, or use object arrays with lower performance." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "xnd(['this', 'is', 'a', 'test', 'notebook'], type='5 * string')" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "xnd(['this', 'is', 'a', 'test', 'notebook']) # xnd" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['this', 'is', 'a', 'test', 'notebook'], dtype='