About 2,180,000 results
Open links in new tab
  1. slice - How slicing in Python works - Stack Overflow

    The previous answers don't discuss multi-dimensional array slicing which is possible using the famous NumPy package: Slicing can also be applied to multi-dimensional arrays.

  2. How do I declare an array in Python? - Stack Overflow

    Aug 23, 2022 · There's no way to say in Python "this variable should never refer to anything other than a list", since Python is dynamically typed. * The default built-in Python type is called a list, not an array. …

  3. python - How can I access the index value in a 'for' loop? - Stack …

    167 Tested on Python 3.12 Here are twelve examples of how you can access the indices with their corresponding array's elements using for loops, while loops and some looping functions. Note that …

  4. Python list vs. array – when to use? - Stack Overflow

    Aug 17, 2022 · Mostly, you should use it when you need to expose a C array to an extension or a system call (for example, ioctl or fctnl). array.array is also a reasonable way to represent a mutable …

  5. How to declare and add items to an array in Python

    The standard library also has the array module, which is a wrapper over C arrays. Like C arrays, array.array objects hold only a single type (which has to be specified at object creation time by using …

  6. python - How do I create an empty array and then append to it in …

    I want to create an empty array and append items to it, one at a time. xs = [] for item in data: xs.append(item) Can I use this list-style notation with NumPy arrays?

  7. python - Check if item is in an array / list - Stack Overflow

    If I've got an array of strings, can I check to see if a string is in the array without doing a for loop? Specifically, I'm looking for a way to do it within an if statement, so something like thi...

  8. Python: How to get values of an array at certain index positions?

    Aug 8, 2014 · 8 Although you ask about numpy arrays, you can get the same behavior for regular Python lists by using operator.itemgetter.

  9. How to find duplicate elements in array using for loop in Python?

    Dec 17, 2009 · In Python 2.7, you can accomplish this with one line: tmp = list(set(list_a)) Comparing the lengths of tmp and list_a at this point should clarify if there were indeed duplicate items in list_a. This …

  10. Array Indexing in Python - Stack Overflow

    Mar 31, 2013 · If you want to replace a range of values in the list, use slicing notation, for example list[2:] (for 'every element from the third to the last'). More generally, the .index method operates on …