13 Matching Annotations
  1. Jul 2023
    1. As you can see, it has sliced along axis 0, the first axis. A slice, therefore, selects a range of elements along an axis. It can be helpful to read the expression arr2d[:2] as "select the first two rows of arr2d."

      Slices follow a similar logic than indexing in NumPy array's. array[:2] selects a range of elements along a single axis,, but array[:2, 1:] does it along two axis.

    1. Tensors on the CPU and NumPy arrays can share their underlying memory locations, and changing one will change the other.

      PyTorch tensors and NumPy arrays share memory locations. This means that changes in one reflect in both.

  2. Apr 2023
    1. dataset['sentimento'] = np.where(dataset['stars'] >= 4, 'bom', 'ruim')

      O código atribui valores à coluna 'sentimento' do dataframe 'dataset' com base em uma condição: se a coluna 'stars' for maior ou igual a 4, o valor atribuído será 'bom', caso contrário, será 'ruim'.

      A função 'np.where' é uma função numpy que permite aplicar uma condição em um array e atribuir valores diferentes dependendo do resultado da condição. No caso do código fornecido, a condição é "dataset['stars'] >= 4", que retorna um array booleano com True para as linhas em que a condição é verdadeira e False para as linhas em que é falsa.

      Em seguida, a função 'np.where' atribui 'bom' para as linhas em que a condição é verdadeira e 'ruim' para as linhas em que é falsa, e essa atribuição é feita para a coluna 'sentimento' do dataframe 'dataset'.

    2. [[39]] [1 2 3 5] [11]

      Ao executar o código fornecido, é criada uma matriz b de uma linha e quatro colunas contendo os valores [1, 2, 3, 5]. Em seguida, a matriz b é transposta, gerando uma matriz de quatro linhas e uma coluna, contendo os mesmos valores.

      A seguir, é realizado o produto escalar entre as matrizes b e c, que resulta em uma matriz de uma linha e uma coluna contendo o valor 39. Esse valor é impresso na saída do programa.

      Em seguida, é calculada a soma dos elementos da matriz b, que é 11 (1 + 2 + 3 + 5). Esse valor é impresso na saída, seguido da soma dos elementos da matriz c, que é a mesma que a soma dos elementos de b, que também é 11. Portanto, a saída do programa é [[39]] [1 2 3 5] [11].

  3. Feb 2021
  4. Oct 2020
    1. numpy.arange([start, ]stop, [step, ]dtype=None

      arange 函数签名

      start 可以缺省,默认值是 0.

      stop 不能缺省, 若是整数则输出的 ndarray 不包括 stop.

    1. That function takes a tuple to specify the size of the output,

      numpy.random.rand() 接收元组作为参数,表示输出的 numpy.ndarray 的形状。

      这和 numpy.ones numpy.zeros 一致

    1. Similar to linspace, but uses a step size (instead of the number of samples).

      linspace 和 arange 的区别是:

      • linspace 用参数 num 指定样本个数
      • arange 用步长指定样本个数
    2. Number of samples to generate.

      参数 num 表示待生成的样本个数,默认值是50

    3. numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0

      endpoint 的默认值是 True,即默认包含 stop 。

  5. May 2020
    1. 还要指出的另一点是,长度和大小都可以从其形状中获得:length实际上是第一维的长度,因此等于shape[0],而size是元素的总数,等于元素中所有元素的乘积形元组。
  6. Oct 2017
    1. c = np.full((2,2), 7) # Create a constant array print(c)

      To avoid the warning, use

      np.full((2,2), 7.) or use explicitly for float np.full((2,2),7, dtype=float) or for int np.full((2,2),7, dtype=int)

  7. Jan 2017
    1. distribution of mean 0 and variance 1 (if any of the are floats, they are first converted to integers by truncation)

      How to create a single random vector or matrix on mean 0 and variance 1