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".

6
  • 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 Commented Oct 26, 2020 at 0: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. Commented Oct 26, 2020 at 1: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... Commented Oct 26, 2020 at 2: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. Commented Oct 26, 2020 at 3: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. Commented Oct 26, 2020 at 3:16

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.