Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

DÚVIDAS__ DIFERENÇAS ENTRE LIST, RANGE, ARANGE E ARRAY

Prezado(a).

Gostaria de saber qual a diferença de LIST, RANGE, ARANGE E ARRAY teoricamente e qual a diferença deles para um mesmo exemplo (favor fazer um exemplo para os 3 casos).

Até o momento, só entendi que LIST, RANGE são fatores específicos do Python e ARANGE e ARRAY são fatores do pacote Numpy e que criam listas.

1 resposta
solução!

Olá Thiago tudo bem com você??

Vamos lá:

List

List
"A list is a collection which is ordered and changeable. In Python lists are written with square brackets."
Em tradução livre, trata-se de um array, é ordenado e mutável, em python a sintaxe é representada por colchetes.

Examplo
Create a List:

thislist = ["apple", "banana", "cherry"]
print(thislist)

['apple', 'banana', 'cherry']

Range:

Definition and Usage
"The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified number."
Em tradução livre, trata-se de uma função que retorna uma sequência iniciando em zero, por padrão, incrementando 1, por padrão também, e parando no número especificado. 

Syntax
range(start, stop, step)

Parameter    Description
start    Optional. An integer number specifying at which position to start. Default is 0
stop    Required. An integer number specifying at which position to stop (not included).
step    Optional. An integer number specifying the incrementation. Default is 1

Exemplo prático:

x = range(3, 20, 2)

for n in x:
  print(n)


3
5
7
9
11
13
15
17
19

Arange:

numpy.arange
numpy.arange([start, ]stop, [step, ]dtype=None)
Return evenly spaced values within a given interval.

Values are generated within the half-open interval [start, stop) (in other words, the interval including start but excluding stop). For integer arguments the function is equivalent to the Python built-in range function, but returns an ndarray rather than a list.
When using a non-integer step, such as 0.1, the results will often not be consistent. It is better to use numpy.linspace for these cases.

Em tradução livre, os valores são gerados dentro do intervalo com início e fim. A função é equivalente à função de intervalo interna do Python, mas retorna um ndarray em vez de uma lista. Indicado na utilização de números inteiros.

Parameters
startnumber, optional
Start of interval. The interval includes this value. The default start value is 0.

stopnumber
End of interval. The interval does not include this value, except in some cases where step is not an integer and floating point round-off affects the length of out.

stepnumber, optional
Spacing between values. For any output out, this is the distance between two adjacent values, out[i+1] - out[i]. The default step size is 1. If step is specified as a position argument, start must also be given.

Returns
arangendarray
Array of evenly spaced values.

np.arange(3)
array([0, 1, 2])
np.arange(3.0)
array([ 0.,  1.,  2.])
np.arange(3,7)
array([3, 4, 5, 6])
np.arange(3,7,2)
array([3, 5])

Array:

Arrays são estruturas de dados semelhantes às listas do Python, mas não tão flexíveis. Em um array todos os elementos devem ser de um mesmo tipo, tipicamente numérico, como int ou float. Além disso, o tamanho de um array não pode ser modificado, ao contrário de listas que podem crescer dinamicamente. 

import numpy as np
>>> a = [[1,2,3], [6,5,4]]
>>> b = np.array(a)
>>> print(a)
[[1, 2, 3], [6, 5, 4]]
>>> print(b)
[[1 2 3]
 [6 5 4]]
>>> type(b)
<class 'numpy.ndarray'>
>>> type(a)
<class 'list'>
>>> c = np.array(a, float)
>>> print(c)
[[ 1.  2.  3.]
 [ 6.  5.  4.]]

Espero que tenha te ajudado e deixado claro as diferenças e os conceitos de cada um. Qualquer coisa é só retornar aqui!

Bons estudos!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software