title: how to type numpy function taking generic array
body: <p>According to the <a href="https://numpy.org/doc/stable/reference/typing.html#numpy.typing.NBitBase" rel="nofollow noreferrer">numpy documentation</a>, to declare a generic numpy type I should use <code>np.floating[T]</code> with <code>T = TypeVar(&quot;T&quot;, bound=npt.NBitBase)</code>. Then NDarray takes a scalar type. How do I combine the two to create a function that takes a generic array of floating? The following:</p>
  <pre class="lang-py prettyprint-override"><code>T = TypeVar(&quot;T&quot;, bound=npt.NBitBase)
  
  
  def entropy(x: npt.NDArray[np.floating[T]]) -&gt; np.floating[T]:
      return cast(np.floating[T], np.sum(x * np.log(x)))
  </code></pre>
  <p>Gives me: <code>TypeError: 'type' object is not subscriptable</code></p>