1

I am examining example Pandas code for creating a MultiIndex:

In [1]: arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
   ...:           ['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
   ...: 

Is this a mistakened use of the term arrays?

From surfing, I find that square brackets delineate Lists. True arrays need to be constructed using the array function of NumPy, as shown here and on SO.

Even though the SO link suggests a conflation of terms, the answers are very clear about the distinction. The Pandas link seems to be authoritative, however, so I want to be 100% sure before I do a mental translation of their every use of "array" into "list".

user36800
  • 2,019
  • 2
  • 19
  • 34
  • 3
    I'm curious how the 'mental translation of their every use of "array" into "list"' would change the code you write or its behavior. For details about Pandas data frames see [underlying data](https://pandas.pydata.org/pandas-docs/stable/user_guide/basics.html#attributes-and-underlying-data) – Mark Oct 26 '20 at 00:57
  • 2
    "array" is often used in a generic sense. Most languages have at least one notion of "array". In Python it is called a "list", but thinking about them as arrays is accurate enough, as long as you don't confuse them with numpy arrays. – John Coleman Oct 26 '20 at 01:00
  • 2
    I'm not sure I would consider NumPy to be the "one true way" of constructing something that is properly called an array, given that Python has a built-in `array` module, defining an object type named `array`... – jasonharper Oct 26 '20 at 02:07
  • @Mark Meyer: Honestly, I don't know how it affects code. I just need a concrete picture of what's going on so that I know what to look up further in an effort to start eking out my own coding. Right now, I rely on partially filled course code and educated guesses from lessons, with much of what's really going on being black magic. – user36800 Oct 26 '20 at 03:16
  • I am uncomfortable with that when applying array operations on complex data structures in a powerful 4th gen language. Thanks to the pointer to the data frame internals. At this point, I'm just trying to understand how terms are used. If "array" is sometimes used loosely, that helps me read the documentation without getting uncertain about my understanding due to discrepancy with other online info. – user36800 Oct 26 '20 at 03:16
  • @John Coleman: The answer seems to be that "array" *is* used loosely in the documentation, and hence, readers should not try to reconcile their understanding with info sources that distinguish "arrays" from "lists". Did you want to post that as the answer? – user36800 Oct 26 '20 at 03:19

1 Answers1

1

Thanks to John Coleman for clarifying that "array[s]" is being used loosely to include the native list. The term should not be automatically interpretted as NumPy arrays. Indeed, as jasonharper points out, NumPy does not have a monopoly on "array" as the name for a class or data structure. Here are two discussions on how to decide on the type of array to use: 1, 2

wjandrea
  • 28,235
  • 9
  • 60
  • 81
user36800
  • 2,019
  • 2
  • 19
  • 34