{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Data Structures\n", "\n", "To keep this documentation generic we typically use dimensions `x` or `y`, but this should *not* be seen as a recommendation to use these labels for anything but actual positions or offsets in space.\n", "\n", "## Variable\n", "\n", "### Basics\n", "\n", "[scipp.Variable](../generated/classes/scipp.Variable.rst#scipp.Variable) is a labeled multi-dimensional array.\n", "A variable has the following key properties:\n", "\n", "- `values`: a multi-dimensional array of values, e.g., a [numpy.ndarray](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)\n", "- `variances`: a (optional) multi-dimensional array of variances for the array values\n", "- `dims`: a list of dimension labels (strings) for each axis of the array\n", "- `unit`: a (optional) physical unit of the values in the array\n", "\n", "Note that variables, unlike [DataArray](data-structures.ipynb#DataArray) and its eponym [xarray.DataArray](http://xarray.pydata.org/en/stable/user-guide/data-structures.html#dataarray), variables do *not* have coordinate dicts." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import scipp as sc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Variables should generally be created using one of the available [creation functions](../reference/api.rst#creation-functions).\n", "For example, we can create a variable from a numpy array:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "var = sc.array(dims=['x', 'y'], values=np.random.rand(2, 4))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "