16 ArraysinPython-JupyterNotebook
16 ArraysinPython-JupyterNotebook
Python Tutorial
Created by Mustafa Germec, PhD
Creating an array
You should import the module name 'array' as follows:
In [4]:
In [5]:
1 # To access more information regarding array, you can execute the following commands
2 help(arr)
NAME
array
DESCRIPTION
This module defines an object type which can efficiently represent
an array of basic values: characters, integers, floating point
numbers. Arrays are sequence types and behave very much like lists,
except that the type of objects stored in them is constrained.
CLASSES
builtins.object
array
Type code
Arrays represent basic values and behave very much like lists, except the type of objects stored in them is
constrained.
The type is specified at object creation time by using a type code, which is a single character.
The following type codes are defined:
In [6]:
0.577
1.618
2.718
3.14
6.0
37.0
1729.0
Accessing
In [7]:
Changing or Updating
In [8]:
Deleting
In [9]:
In [10]:
Concatenation
In [11]:
The new array called special_fibonacci_nums is array('d', [0.577, 1.618, 2.718, 3.14, 6.0, 37.0, 1729.0, 1.
0, 1.0, 2.0, 3.0, 5.0, 8.0, 13.0, 21.0, 34.0]).
Creating ID arrays
In [12]:
1 mult = 10
2 one_array = [1]*mult
3 print(one_array)
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
In [13]:
1 mult = 10
2 nums_array = [i for i in range(mult)]
3 print(nums_array)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
In [14]:
In [15]:
In [16]:
In [17]:
Slicing
In [18]:
In [19]:
In [20]:
In [21]:
In [22]:
Searching
In [23]:
Copying
In [24]:
array('d', [0.577, 1.618, 2.718, 3.14, 6.0, 37.0, 1729.0]) with the ID number 2668250199472
array('d', [0.577, 1.618, 2.718, 3.14, 6.0, 37.0, 1729.0]) with the ID number 2668250199472
0.577 1.618 2.718 3.14 6.0 37.0 1729.0
The ID number of the array special_nums is 2668250199472.
0.577 1.618 2.718 3.14 6.0 37.0 1729.0
The ID number of the array copied_special_nums is 2668250199472.
In [25]:
[5.770e-01 1.618e+00 2.718e+00 3.140e+00 6.000e+00 3.700e+01 1.729e+03] with the ID number 2668
248532144
[5.770e-01 1.618e+00 2.718e+00 3.140e+00 6.000e+00 3.700e+01 1.729e+03] with the ID number 2668
254732400
0.577 1.618 2.718 3.14 6.0 37.0 1729.0
0.577 1.618 2.718 3.14 6.0 37.0 1729.0
In [26]:
[5.770e-01 1.618e+00 2.718e+00 3.140e+00 6.000e+00 3.700e+01 1.729e+03] with the ID number 2668
254735376
[5.770e-01 1.618e+00 2.718e+00 3.140e+00 6.000e+00 3.700e+01 1.729e+03] with the ID number 2668
254736144
0.577 1.618 2.718 3.14 6.0 37.0 1729.0
0.577 1.618 2.718 3.14 6.0 37.0 1729.0