Python Array Data Structure: Difference between revisions
Jump to navigation
Jump to search
(Redirected page to Python Array) |
m (Text replacement - ". ----" to ". ----") |
||
(10 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
A [[Python Array Data Structure]] is an [[array data structure]] that is a [[Python data structure]]. | |||
* <B>Context</U>:</B> | |||
** It can range from being a [[Python Built-In Array]] to being a [[Python Library Array]] to being a [[Python Custom Array]]. | |||
** It can support a [[Python Array Operation]]. | |||
** It can be the input to an [[Array-input Python Subroutine]], such as a [[Python Join Subroutine]]. | |||
** It can range from being | |||
*** a [[Python Tuple]], | |||
*** a [[Python Vector]], | |||
*** a [[Python Array of Arrays]], such as a [[Python Matrix]], | |||
*** a [[Python Array of Hashes]]. | |||
* <B>Example(s):</B> | |||
** a [[Python List Data Structure]]. | |||
** a [[Numpy Matrix Data Structure]]. | |||
** a [[Numpy Array]]. | |||
** a [[Pandas DataFrame Data Structure]]. | |||
** … | |||
* <B>Counter-Example(s):</B> | |||
** a [[Python Dictionary Data Structure]]. | |||
** a [[Perl Array Data Structure]]. | |||
* <B>See:</B> [[Python Coding Example]], [[Python Built-In Datatype]]. | |||
---- | |||
---- | |||
== References == | |||
* https://docs.python.org/2/library/array.html | |||
=== Examples === | |||
; Import libraries | |||
<PRE> | |||
import numpy as np | |||
import pandas as pd | |||
</PRE> | |||
; [[Empty array]] | |||
<PRE> | |||
df = pd.DataFrame(columns=['col1','col2']) | |||
df = pd.DataFrame(np.zeros(0, dtype=[('col1', 'i7'),('col2', 'a50')])) | |||
</PRE> | |||
; Populate manually | |||
<PRE> | |||
Matrix = [ [0 for x in xrange(5)] for y in xrange(6)] | |||
Matrix[4][3] = 99 | |||
Matrix | |||
xx = np.array([2, 4, -11]) | |||
yy = zeros(3, Int) # Create empty array ready to receive result | |||
</pre> | |||
; Populate from a file. | |||
<pre> | |||
</pre> | |||
; Loops | |||
<pre> | |||
for i in range(0, 3): | |||
Matrix[i] = i * 2 | |||
print yy | |||
# [ 4 8 -22] | |||
</pre> | |||
; Transforming into a string | |||
<pre> | |||
</pre> | |||
; Emptying | |||
<pre> | |||
</pre> | |||
; Random | |||
<pre> | |||
import random; | |||
#Generate 1000 random integer numbers which are between 1 and 9999(included). | |||
Z=random.sample(range(1,9999),1000); | |||
type(Z) | |||
</pre> | |||
---- | |||
__NOTOC__ | |||
[[Category:Concept]] |
Latest revision as of 00:03, 23 September 2021
A Python Array Data Structure is an array data structure that is a Python data structure.
- Context:
- It can range from being a Python Built-In Array to being a Python Library Array to being a Python Custom Array.
- It can support a Python Array Operation.
- It can be the input to an Array-input Python Subroutine, such as a Python Join Subroutine.
- It can range from being
- a Python Tuple,
- a Python Vector,
- a Python Array of Arrays, such as a Python Matrix,
- a Python Array of Hashes.
- Example(s):
- Counter-Example(s):
- See: Python Coding Example, Python Built-In Datatype.
References
Examples
- Import libraries
import numpy as np import pandas as pd
df = pd.DataFrame(columns=['col1','col2']) df = pd.DataFrame(np.zeros(0, dtype=[('col1', 'i7'),('col2', 'a50')]))
- Populate manually
Matrix = [ [0 for x in xrange(5)] for y in xrange(6)] Matrix[4][3] = 99 Matrix xx = np.array([2, 4, -11]) yy = zeros(3, Int) # Create empty array ready to receive result
- Populate from a file.
- Loops
for i in range(0, 3): Matrix[i] = i * 2 print yy # [ 4 8 -22]
- Transforming into a string
- Emptying
- Random
import random; #Generate 1000 random integer numbers which are between 1 and 9999(included). Z=random.sample(range(1,9999),1000); type(Z)