{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "choice-lender",
   "metadata": {},
   "outputs": [],
   "source": [
    "eng=\"one minute a voice said and the time buzzer sounded\"\n",
    "chn=\"可控是病毒武器最基本的要求\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ruled-kuwait",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "o\n",
      "n\n",
      "e\n",
      " \n",
      "m\n",
      "i\n",
      "n\n",
      "u\n",
      "t\n",
      "e\n",
      " \n",
      "a\n",
      " \n",
      "v\n",
      "o\n",
      "i\n",
      "c\n",
      "e\n",
      " \n",
      "s\n",
      "a\n",
      "i\n",
      "d\n",
      " \n",
      "a\n",
      "n\n",
      "d\n",
      " \n",
      "t\n",
      "h\n",
      "e\n",
      " \n",
      "t\n",
      "i\n",
      "m\n",
      "e\n",
      " \n",
      "b\n",
      "u\n",
      "z\n",
      "z\n",
      "e\n",
      "r\n",
      " \n",
      "s\n",
      "o\n",
      "u\n",
      "n\n",
      "d\n",
      "e\n",
      "d\n"
     ]
    }
   ],
   "source": [
    "for char in eng:\n",
    "    print(char)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "passive-petite",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "可\n",
      "控\n",
      "是\n",
      "病\n",
      "毒\n",
      "武\n",
      "器\n",
      "最\n",
      "基\n",
      "本\n",
      "的\n",
      "要\n",
      "求\n"
     ]
    }
   ],
   "source": [
    "for char in chn:\n",
    "    print(char)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "olympic-realtor",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "one\n",
      "minute\n",
      "a\n",
      "voice\n",
      "said\n",
      "and\n",
      "the\n",
      "time\n",
      "buzzer\n",
      "sounded\n"
     ]
    }
   ],
   "source": [
    "for word in eng.split():\n",
    "    print(word)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "induced-enhancement",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "可控是病毒武器最基本的要求\n"
     ]
    }
   ],
   "source": [
    "for word in chn.split():\n",
    "    print(word)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "lovely-bottle",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'StringIO'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-9-3e4825b8299f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mStringIO\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'StringIO'"
     ]
    }
   ],
   "source": [
    "import StringIO"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "interested-cardiff",
   "metadata": {},
   "outputs": [],
   "source": [
    "from io import StringIO"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "portable-ivory",
   "metadata": {},
   "outputs": [],
   "source": [
    "inputs = StringIO()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "compatible-destination",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "64"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inputs.write(\"nor is mister quilter's manner less interesting than his matter\" + '\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "federal-margin",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "nor is mister quilter's manner less interesting than his matternor is mister quilter's manner less interesting than his matter\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(inputs.getvalue())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "consecutive-entity",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "64"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inputs.write(\"nor is mister quilter's manner less interesting than his matter\" + '\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "desirable-anxiety",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "nor is mister quilter's manner less interesting than his matternor is mister quilter's manner less interesting than his matter\n",
      "nor is mister quilter's manner less interesting than his matter\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(inputs.getvalue())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "employed-schedule",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tempfile"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "unlikely-honduras",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__ne__', '__new__', '__next__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_checkClosed', '_checkReadable', '_checkSeekable', '_checkWritable', '_dealloc_warn', '_finalizing', 'close', 'closed', 'detach', 'fileno', 'flush', 'isatty', 'mode', 'name', 'peek', 'raw', 'read', 'read1', 'readable', 'readinto', 'readinto1', 'readline', 'readlines', 'seek', 'seekable', 'tell', 'truncate', 'writable', 'write', 'writelines']\n",
      "57\n"
     ]
    }
   ],
   "source": [
    "with tempfile.TemporaryFile() as fp:\n",
    "    print(dir(fp))\n",
    "    print(fp.name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "needed-trail",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = tempfile.mkstemp(suffix=None, prefix='test', dir=None, text=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "hazardous-choir",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']\n"
     ]
    }
   ],
   "source": [
    "print(dir(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "front-sauce",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(57, '/tmp/test27smzbzc')\n"
     ]
    }
   ],
   "source": [
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "shared-wages",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<built-in method index of tuple object at 0x7f999b525648>\n"
     ]
    }
   ],
   "source": [
    "print(a.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "charged-carnival",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_closer', 'close', 'delete', 'file', 'name']\n",
      "/tmp/tmpfjn7mygy\n"
     ]
    }
   ],
   "source": [
    "fp= tempfile.NamedTemporaryFile(mode='w', delete=False)\n",
    "print(dir(fp))\n",
    "print(fp.name)\n",
    "fp.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "religious-terror",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/tmp/tmpfjn7mygy\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "os.path.exists(fp.name)\n",
    "print(fp.name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "communist-gospel",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<function BufferedRandom.write(buffer, /)>"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fp.write"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "simplified-clarity",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'example'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s='/home/ubuntu/python/example.py'\n",
    "os.path.splitext(os.path.basename(s))[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "popular-genius",
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import Counter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "studied-burner",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_items([('hello', 1), ('world', 1)])\n"
     ]
    }
   ],
   "source": [
    "counter = Counter()\n",
    "counter.update([\"hello\"])\n",
    "counter.update([\"world\"])\n",
    "print(counter.items())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "mineral-ceremony",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_items([('h', 1), ('e', 1), ('l', 3), ('o', 2), ('w', 1), ('r', 1), ('d', 1)])\n"
     ]
    }
   ],
   "source": [
    "counter = Counter()\n",
    "counter.update(\"hello\")\n",
    "counter.update(\"world\")\n",
    "print(counter.items())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "nonprofit-freedom",
   "metadata": {},
   "outputs": [],
   "source": [
    "counter.update(list(\"hello\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "extended-methodology",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_items([('h', 2), ('e', 2), ('l', 5), ('o', 3), ('w', 1), ('r', 1), ('d', 1)])\n"
     ]
    }
   ],
   "source": [
    "print(counter.items())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "grand-benjamin",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['h', 'e', 'l', 'l', 'o']"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(\"hello\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "marine-fundamentals",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n"
     ]
    }
   ],
   "source": [
    "from io import StringIO\n",
    "a = StringIO(initial_value='{}', newline='')\n",
    "print(a.read())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "suitable-charlotte",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "expected str, bytes or os.PathLike object, not _io.StringIO",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-56-4323a912120d>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mwith\u001b[0m \u001b[0mio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m     \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mTypeError\u001b[0m: expected str, bytes or os.PathLike object, not _io.StringIO"
     ]
    }
   ],
   "source": [
    "with io.open(a) as f:\n",
    "    print(f.read())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "institutional-configuration",
   "metadata": {},
   "outputs": [],
   "source": [
    "io.open?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "pregnant-modem",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_default_args(fn):\n",
    "    if fn is None:\n",
    "        return {}\n",
    "\n",
    "    signature = inspect.signature(fn)\n",
    "    return {\n",
    "        k: v.default\n",
    "        for k, v in signature.parameters.items()\n",
    "        if v.default is not inspect.Parameter.empty\n",
    "    }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "first-release",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'inspect' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-59-8f782d06097f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mget_default_args\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m<ipython-input-58-cb5a8794f39f>\u001b[0m in \u001b[0;36mget_default_args\u001b[0;34m(fn)\u001b[0m\n\u001b[1;32m      3\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m     \u001b[0msignature\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0minspect\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msignature\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      6\u001b[0m     return {\n\u001b[1;32m      7\u001b[0m         \u001b[0mk\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdefault\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'inspect' is not defined"
     ]
    }
   ],
   "source": [
    "get_default_args(io.open)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "convertible-roulette",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: sox in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (1.4.1)\n",
      "Requirement already satisfied: numpy>=1.9.0 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from sox) (1.20.1)\n",
      "Requirement already satisfied: librosa in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (0.8.0)\n",
      "Requirement already satisfied: scikit-learn!=0.19.0,>=0.14.0 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from librosa) (0.24.1)\n",
      "Requirement already satisfied: numba>=0.43.0 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from librosa) (0.52.0)\n",
      "Requirement already satisfied: pooch>=1.0 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from librosa) (1.3.0)\n",
      "Requirement already satisfied: scipy>=1.0.0 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from librosa) (1.2.1)\n",
      "Requirement already satisfied: numpy>=1.15.0 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from librosa) (1.20.1)\n",
      "Requirement already satisfied: decorator>=3.0.0 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from librosa) (4.4.2)\n",
      "Requirement already satisfied: resampy>=0.2.2 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from librosa) (0.2.2)\n",
      "Requirement already satisfied: audioread>=2.0.0 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from librosa) (2.1.9)\n",
      "Requirement already satisfied: soundfile>=0.9.0 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from librosa) (0.9.0.post1)\n",
      "Requirement already satisfied: joblib>=0.14 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from librosa) (1.0.1)\n",
      "Requirement already satisfied: setuptools in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from numba>=0.43.0->librosa) (51.0.0)\n",
      "Requirement already satisfied: llvmlite<0.36,>=0.35.0 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from numba>=0.43.0->librosa) (0.35.0)\n",
      "Requirement already satisfied: appdirs in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from pooch>=1.0->librosa) (1.4.4)\n",
      "Requirement already satisfied: packaging in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from pooch>=1.0->librosa) (20.9)\n",
      "Requirement already satisfied: requests in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from pooch>=1.0->librosa) (2.25.1)\n",
      "Requirement already satisfied: six>=1.3 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from resampy>=0.2.2->librosa) (1.15.0)\n",
      "Requirement already satisfied: threadpoolctl>=2.0.0 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from scikit-learn!=0.19.0,>=0.14.0->librosa) (2.1.0)\n",
      "Requirement already satisfied: cffi>=0.6 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from soundfile>=0.9.0->librosa) (1.14.4)\n",
      "Requirement already satisfied: pycparser in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from cffi>=0.6->soundfile>=0.9.0->librosa) (2.20)\n",
      "Requirement already satisfied: pyparsing>=2.0.2 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from packaging->pooch>=1.0->librosa) (2.4.7)\n",
      "Requirement already satisfied: idna<3,>=2.5 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from requests->pooch>=1.0->librosa) (2.10)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from requests->pooch>=1.0->librosa) (2020.12.5)\n",
      "Requirement already satisfied: chardet<5,>=3.0.2 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from requests->pooch>=1.0->librosa) (4.0.0)\n",
      "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from requests->pooch>=1.0->librosa) (1.26.3)\n"
     ]
    }
   ],
   "source": [
    "!pip install sox\n",
    "!pip install librosa"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "cutting-fleece",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.float64'>\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import sox\n",
    "tfm = sox.Transformer()\n",
    "sample_rate = 44100\n",
    "y = np.sin(2 * np.pi * 440.0 * np.arange(sample_rate * 1.0) / sample_rate)\n",
    "print(y.dtype.type)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "historical-diving",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.          0.06264832  0.12505052 ... -0.18696144 -0.12505052\n",
      " -0.06264832]\n"
     ]
    }
   ],
   "source": [
    "output_array = tfm.build_array(input_array=y, sample_rate_in=sample_rate)\n",
    "print(output_array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "similar-spice",
   "metadata": {},
   "outputs": [],
   "source": [
    "tfm.build_array?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "grand-influence",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['8svx', 'aif', 'aifc', 'aiff', 'aiffc', 'al', 'amb', 'amr-nb', 'amr-wb', 'anb', 'au', 'avr', 'awb', 'caf', 'cdda', 'cdr', 'cvs', 'cvsd', 'cvu', 'dat', 'dvms', 'f32', 'f4', 'f64', 'f8', 'fap', 'flac', 'fssd', 'gsm', 'gsrt', 'hcom', 'htk', 'ima', 'ircam', 'la', 'lpc', 'lpc10', 'lu', 'mat', 'mat4', 'mat5', 'maud', 'nist', 'ogg', 'paf', 'prc', 'pvf', 'raw', 's1', 's16', 's2', 's24', 's3', 's32', 's4', 's8', 'sb', 'sd2', 'sds', 'sf', 'sl', 'sln', 'smp', 'snd', 'sndfile', 'sndr', 'sndt', 'sou', 'sox', 'sph', 'sw', 'txw', 'u1', 'u16', 'u2', 'u24', 'u3', 'u32', 'u4', 'u8', 'ub', 'ul', 'uw', 'vms', 'voc', 'vorbis', 'vox', 'w64', 'wav', 'wavpcm', 'wv', 'wve', 'xa', 'xi']\n"
     ]
    }
   ],
   "source": [
    "print(sox.core._get_valid_formats())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "wireless-hypothetical",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "float64\n",
      "(59471,)\n",
      "16000\n",
      "(54065,)\n",
      "1.0999907518727459\n"
     ]
    }
   ],
   "source": [
    "import soundfile as sf\n",
    "wav='/workspace/DeepSpeech-2.x/examples/aishell/s1/../../..//examples/dataset/aishell/data_aishell/wav/dev/S0724/BAC009S0724W0190.wav'\n",
    "samples, sr = sf.read(wav)\n",
    "print(samples.dtype)\n",
    "print(samples.shape)\n",
    "print(sr)\n",
    "tfm = sox.Transformer()\n",
    "tfm.speed(1.1)\n",
    "output_array = tfm.build_array(input_array=samples, sample_rate_in=sr)\n",
    "output_array.dtype\n",
    "print(output_array.shape)\n",
    "print(len(samples)/len(output_array))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "designed-fluid",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/x-wav;base64,[encoded data, 158648 characters]\" type=\"audio/x-wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import IPython.display as ipd\n",
    "ipd.Audio(wav) # load a local WAV file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "cultural-friendship",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 158648 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tfm = sox.Transformer()\n",
    "tfm.speed(1.0)\n",
    "output_array = tfm.build_array(input_array=samples, sample_rate_in=sr)\n",
    "ipd.Audio(output_array, rate=sr) # load a NumPy array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "fossil-lotus",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 144232 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tfm = sox.Transformer()\n",
    "tfm.speed(1.1)\n",
    "output_array = tfm.build_array(input_array=samples, sample_rate_in=sr)\n",
    "ipd.Audio(output_array, rate=sr) # load a NumPy array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "constitutional-poker",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 176272 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tfm = sox.Transformer()\n",
    "tfm.speed(0.9)\n",
    "output_array = tfm.build_array(input_array=samples, sample_rate_in=sr)\n",
    "ipd.Audio(output_array, rate=sr) # load a NumPy array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "threaded-strap",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "66078\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 20736 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "librosa.display.waveplot(samples_out, sr=sr)\n",
    "print(len(samples_out))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "infectious-welcome",
   "metadata": {},
   "outputs": [],
   "source": [
    "import librosa\n",
    "x, sr = librosa.load(wav, sr=16000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "musical-anatomy",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "float32\n",
      "float64\n"
     ]
    }
   ],
   "source": [
    "print(x.dtype)\n",
    "print(samples.dtype)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "lucky-paraguay",
   "metadata": {},
   "outputs": [],
   "source": [
    "sf.read?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "annual-christmas",
   "metadata": {},
   "outputs": [],
   "source": [
    "librosa.load?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "infectious-seeker",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.allclose(x, samples)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "pregnant-conditioning",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "logical-happiness",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.random.uniform?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "rocky-plastic",
   "metadata": {},
   "outputs": [],
   "source": [
    "random.uniform?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "focused-compensation",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.random.RandomState?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "centered-repository",
   "metadata": {},
   "outputs": [],
   "source": [
    "random.sample?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "inner-invite",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['3', '5'], dtype='<U1')"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.choice(['5','4', '3'], 2, replace=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "russian-chosen",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['3', '4']"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.sample(['5','4', '3'], 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "equal-particle",
   "metadata": {},
   "outputs": [],
   "source": [
    "def change_speed(samples, speed_rate):\n",
    "    \"\"\"Change the audio speed by linear interpolation.\n",
    "\n",
    "    Note that this is an in-place transformation.\n",
    "\n",
    "    :param speed_rate: Rate of speed change:\n",
    "                       speed_rate > 1.0, speed up the audio;\n",
    "                       speed_rate = 1.0, unchanged;\n",
    "                       speed_rate < 1.0, slow down the audio;\n",
    "                       speed_rate <= 0.0, not allowed, raise ValueError.\n",
    "    :type speed_rate: float\n",
    "    :raises ValueError: If speed_rate <= 0.0.\n",
    "    \"\"\"\n",
    "    if speed_rate <= 0:\n",
    "        raise ValueError(\"speed_rate should be greater than zero.\")\n",
    "    old_length = samples.shape[0]\n",
    "    new_length = int(old_length / speed_rate)\n",
    "    old_indices = np.arange(old_length)\n",
    "    new_indices = np.linspace(start=0, stop=old_length, num=new_length)\n",
    "    samples = np.interp(new_indices, old_indices, samples)\n",
    "    return samples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "tracked-purse",
   "metadata": {},
   "outputs": [],
   "source": [
    "samples, sr = sf.read(wav)\n",
    "samples_out = change_speed(samples, 1.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "steady-mileage",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 158648 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ipd.Audio(samples, rate=sr) # load a NumPy array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "regulated-google",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 158648 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ipd.Audio(samples_out, rate=sr) # load a NumPy array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "homeless-forge",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 144232 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "samples_out = change_speed(samples, 1.1)\n",
    "ipd.Audio(samples_out, rate=sr) # load a NumPy array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "exciting-blocking",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "                <audio  controls=\"controls\" >\n",
       "                    <source src=\"data:audio/wav;base64,[encoded data, 176268 characters]\" type=\"audio/wav\" />\n",
       "                    Your browser does not support the audio element.\n",
       "                </audio>\n",
       "              "
      ],
      "text/plain": [
       "<IPython.lib.display.Audio object>"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "samples_out = change_speed(samples, 0.9)\n",
    "ipd.Audio(samples_out, rate=sr) # load a NumPy array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "through-botswana",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "66078\n"
     ]
    }
   ],
   "source": [
    "print(len(samples_out))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "cellular-violence",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting matplotlib\n",
      "  Downloading matplotlib-3.4.1-cp37-cp37m-manylinux1_x86_64.whl (10.3 MB)\n",
      "\u001b[K     |████████████████████████████████| 10.3 MB 691 kB/s eta 0:00:01\n",
      "\u001b[?25hRequirement already satisfied: pillow>=6.2.0 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from matplotlib) (8.1.0)\n",
      "Requirement already satisfied: numpy>=1.16 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from matplotlib) (1.20.1)\n",
      "Requirement already satisfied: python-dateutil>=2.7 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from matplotlib) (2.8.1)\n",
      "Collecting kiwisolver>=1.0.1\n",
      "  Downloading kiwisolver-1.3.1-cp37-cp37m-manylinux1_x86_64.whl (1.1 MB)\n",
      "\u001b[K     |████████████████████████████████| 1.1 MB 45.9 MB/s eta 0:00:01\n",
      "\u001b[?25hRequirement already satisfied: pyparsing>=2.2.1 in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from matplotlib) (2.4.7)\n",
      "Collecting cycler>=0.10\n",
      "  Downloading cycler-0.10.0-py2.py3-none-any.whl (6.5 kB)\n",
      "Requirement already satisfied: six in /workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages (from cycler>=0.10->matplotlib) (1.15.0)\n",
      "Installing collected packages: kiwisolver, cycler, matplotlib\n",
      "Successfully installed cycler-0.10.0 kiwisolver-1.3.1 matplotlib-3.4.1\n"
     ]
    }
   ],
   "source": [
    "!pip install matplotlib\n",
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "import librosa.display"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "undefined-parade",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PolyCollection at 0x7f6a2594afd0>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 20736 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "librosa.display.waveplot(samples_out, sr=sr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "special-delicious",
   "metadata": {},
   "outputs": [],
   "source": [
    "import getpass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "seasonal-consensus",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['GetPassWarning',\n",
       " '__all__',\n",
       " '__builtins__',\n",
       " '__cached__',\n",
       " '__doc__',\n",
       " '__file__',\n",
       " '__loader__',\n",
       " '__name__',\n",
       " '__package__',\n",
       " '__spec__',\n",
       " '_raw_input',\n",
       " 'contextlib',\n",
       " 'fallback_getpass',\n",
       " 'getpass',\n",
       " 'getuser',\n",
       " 'io',\n",
       " 'os',\n",
       " 'sys',\n",
       " 'termios',\n",
       " 'unix_getpass',\n",
       " 'warnings',\n",
       " 'win_getpass']"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dir(getpass)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "dress-distinction",
   "metadata": {},
   "outputs": [],
   "source": [
    "getpass?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "rental-anthony",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Worker:"
     ]
    }
   ],
   "source": [
    "import multiprocessing\n",
    "import cProfile\n",
    "import time\n",
    "\n",
    "def worker(num):\n",
    "    time.sleep(3)\n",
    "    print('Worker:', num)\n",
    "\n",
    "def profile_worker(num):\n",
    "    cProfile.runctx('worker(num)', globals(), locals(), 'profile-%d.out' %num)\n",
    "\n",
    "\n",
    "\n",
    "for i in range(5):\n",
    "    p = multiprocessing.Process(target=profile_worker, args=(i,))\n",
    "    p.start()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "separated-restriction",
   "metadata": {},
   "outputs": [],
   "source": [
    "!ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "painted-variable",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2, 2)\n",
      "[ 1 20]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "l = [(1, 20), (2, 30)]\n",
    "scores = np.array(l)\n",
    "print(scores.shape)\n",
    "print(scores[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "satellite-insider",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1]\n"
     ]
    }
   ],
   "source": [
    "sort_idx = np.argsort(scores[:, -1])\n",
    "print(sort_idx)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "developed-thirty",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1 20]\n",
      " [ 2 30]]\n"
     ]
    }
   ],
   "source": [
    "sorted_val_scores = scores[sort_idx][::1]\n",
    "print(sorted_val_scores)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "official-bench",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1 20]\n",
      " [ 2 30]]\n"
     ]
    }
   ],
   "source": [
    "sorted_val_scores = scores[sort_idx]\n",
    "print(sorted_val_scores)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ranking-camera",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b'\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x14\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x1e\\x00\\x00\\x00\\x00\\x00\\x00\\x00'\n",
      "[ 1 20  2 30]\n",
      "[[ 1 20]\n",
      " [ 2 30]]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages/ipykernel_launcher.py:1: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n",
      "/workspace/DeepSpeech-2.x/tools/venv/lib/python3.7/site-packages/ipykernel_launcher.py:3: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead\n",
      "  This is separate from the ipykernel package so we can avoid doing imports until\n"
     ]
    }
   ],
   "source": [
    "a = scores.tostring()\n",
    "print(a)\n",
    "b = np.fromstring(a, scores.dtype)\n",
    "print(b)\n",
    "print(scores)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "breeding-proxy",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.int16"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.int16"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "coordinate-hungary",
   "metadata": {},
   "outputs": [],
   "source": [
    "dtype = np.dtype('int16')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "specified-jackson",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "int16\n",
      "16\n"
     ]
    }
   ],
   "source": [
    "print(dtype)\n",
    "dtype is np.int16\n",
    "print(np.iinfo(dtype).bits)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "activated-insight",
   "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.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
