NumPy Typecodes Cheatsheet

<p>If you&rsquo;ve used&nbsp;<a href="https://betterprogramming.pub/numpy-illustrated-the-visual-guide-to-numpy-3b1d4976de1d?sk=57b908a77aa44075a49293fa1631dd9b" rel="noopener ugc nofollow" target="_blank">NumPy</a>&nbsp;long enough, you&rsquo;ve most probably run into those incomprehensible type abbreviations and were supposedly most annoyed by them. Gradually NumPy replaces them with something more readable, but internally they are still present, and they frequently leak out here and there.</p> <p>There are several ways to specify a data type in NumPy. You can do it:</p> <ul> <li>as a type object:&nbsp;<code>np.array([1,2,3], dtype=np.int16)</code></li> <li>as a string:&nbsp;<code>np.array([1,2,3], dtype=&#39;int16&#39;)</code></li> <li>as an array protocol abbreviation:&nbsp;<code>np.array([1,2,3], dtype=&#39;&gt;i2&#39;)</code></li> <li>as a NumPy &ldquo;1-char string typecode&rdquo;:&nbsp;<code>np.array([1,2,3], dtype=&#39;h&#39;)</code></li> </ul> <p>with the last variant being the least readable of them all.</p> <p>A usual scenario where you might want to use array protocol is decoding raw data (as read from a file, a network bytestream, etc.).</p> <p>As for &ldquo;1-char string typecode&rdquo; use cases, you can stumble into it when you create an array from a string:</p> <p><a href="https://betterprogramming.pub/numpy-typecodes-cheatsheet-1c4cd8fd2318"><strong>Click Here</strong></a></p>