851 - 900 Flashcards

1
Q

numpy.random.shuffle()

A

This function only shuffles the array along the first axis of a multi-dimensional array.

arr = np.arange(10)
np.random.shuffle(arr)
πŸ‘‰ [1 7 5 2 9 4 3 6 0 8]
arr = np.arange(9).reshape((3, 3))
np.random.shuffle(arr)

arr
πŸ‘‰ array([[3, 4, 5],
          [6, 7, 8],
          [0, 1, 2]])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

numpy.transpose(a, axes=None)

A

Reverse or permute the axes of an array and returns the modified array.

x = np.array([[0, 1],
              [2, 3]])

print(np.transpose(x))
πŸ‘‰ [[0 2]
    [1 3]]
my_array = numpy.array([[1,2,3],
                        [4,5,6]])

print(numpy.transpose(my_array))
πŸ‘‰ [[1 4]
    [2 5]
    [3 6]]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

numpy.append(arr, values, axis=None)

A

Append values to the end of an array.

np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]])
πŸ‘‰ array([1, 2, 3, ..., 7, 8, 9])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

numpy.inner(a, b, /)

A

Inner product of two arrays. Ordinary inner product of vectors for 1-D arrays.

a = np.array([1,2,3])
b = np.array([0,1,0])

print(np.inner(a, b))
πŸ‘‰ 2
A = numpy.array([0, 1])
B = numpy.array([3, 4])

print(numpy.inner(A, B))
πŸ‘‰ 4
A = numpy.array([2, 1])
B = numpy.array([3, 4])

print(numpy.inner(A, B))
πŸ‘‰ 10
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

numpy.outer(a, b, out=None)

A

Compute the outer product of two vectors.

A = numpy.array([2, 3])
B = numpy.array([3, 4])
print(numpy.outer(A, B))
πŸ‘‰ [[ 6  8]
    [ 9 12]]
A = numpy.array([0, 1])
B = numpy.array([3, 4])
print numpy.outer(A, B) 
πŸ‘‰ [[0 0]
    [3 4]]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Array Broadcasting

A

describes how NumPy treats arrays with different shapes during arithmetic operations. Subject to certain constraints, the smaller array is β€œbroadcast” across the larger array so that they have compatible shapes.

if Rows_1 == Rows_2 and Colums_1 == Colums_2:
	compatible

if (Rows_1 == 1 or Colums_1 == 1) and (Rows_2 == 1 or Colums_2 == 1):
	compatible

if (Rows_1 == 1 or Colums_1 == 1) and (Rows_1 == Rows_2 or Colums_1 == Colums_2)
	compatible

x.shape == (2, 3)

y.shape == (2, 3) --- compatible
y.shape == (2, 1) --- compatible
y.shape == (1, 3) --- compatible
y.shape == (3, )  --- compatible

y.shape == (3, 2) --- NOT_compatible
y.shape == (2,  ) --- NOT_compatible

x.shape == (1, 2, 3, 5, 1, 11, 1, 17)

y.shape ==          (1, 7, 1,  1, 17)  --- compatible
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

numpy.empty(shape, dtype=float, order=’C’, *, like=None)

🎯 shape β€” int or tuple of int β€” Shape of the empty array, e.g., (2, 3) or 2.
🎯 order β€” {β€˜C’, β€˜F’}, optional, default: β€˜C’ β€” Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.

A

Return a new array of given shape and type, without initializing entries.

np.empty([2, 2])
πŸ‘‰ array([[ -9.74499359e+001,   6.69583040e-309],
          [  2.13182611e-314,   3.06959433e-309]])
np.empty([2, 2], dtype=int)
πŸ‘‰ array([[-1073741821, -1067949133],
          [  496041986,    19249760]])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

numpy.diag(v, k=0)

A

Extract a diagonal or construct a diagonal array.

x = array([[0, 1, 2],
           [3, 4, 5],
           [6, 7, 8]])

np.diag(x)
πŸ‘‰ array([0, 4, 8])

np.diag(x, k=1)
πŸ‘‰ array([1, 5])

np.diag(x, k=-1)
πŸ‘‰ array([3, 7])

np.diag(np.diag(x))
πŸ‘‰ array([[0, 0, 0],
          [0, 4, 0],
          [0, 0, 8]])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

numpy.zeros(shape, dtype=float, order=’C’, *, like=None)

A

Return a new array of given shape and type, filled with zeros.

np.zeros(5)
πŸ‘‰ array([ 0.,  0.,  0.,  0.,  0.])
np.zeros((5,), dtype=int)
πŸ‘‰ array([0, 0, 0, 0, 0])
np.zeros((2, 1))
πŸ‘‰ array([[ 0.],
          [ 0.]])
s = (2,2)
np.zeros(s)
πŸ‘‰ array([[ 0.,  0.],
          [ 0.,  0.]])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

numpy.genfromtxt()

A

Load data from a text file, with missing values handled as specified.

f = StringIO('''text,# of chars hello world,11 numpy,5''')

np.genfromtxt(f, dtype='S12,S12', delimiter=',')
πŸ‘‰ array([(b'text', b''), (b'hello world', b'11'), (b'numpy', b'5')], 
   dtype=[('f0', 'S12'), ('f1', 'S12')])

s = StringIO(u"1,1.3,abcde")
data = np.genfromtxt(s, dtype=[('myint','i8'),('myfloat','f8'), ('mystring','S5')], delimiter=",")

data
πŸ‘‰ array((1, 1.3, b'abcde'), dtype=[('myint', '<i8'), ('myfloat', '<f8'), ('mystring', 'S5')])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

numpy.stack(arrays, axis=0, out=None)

A

Join a sequence of arrays along a new axis.

a = np.array([1, 2, 3])
b = np.array([4, 5, 6])

np.stack((a, b))
πŸ‘‰ array([[1, 2, 3],
          [4, 5, 6]])
np.stack((a, b), axis=-1)
πŸ‘‰ array([[1, 4],
          [2, 5],
          [3, 6]])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

numpy.squeeze(a, axis=None)

A

Remove axes of length.

x = np.array([[[0], [1], [2]]])

print(np.squeeze(x))
πŸ‘‰ [0 1 2]
x = np.array([[[0], [1], [2]]])

print(np.squeeze(x, axis=0))
πŸ‘‰ [[0]
    [1]
    [2]]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

pyment

🎯 pip install pyment - install
🎯 pyment -h - get the available options
🎯 python setup.py test - run the unit-tests:

A

docstrings manager (creator/converter)

To run Pyment from the command line the easiest way is to provide a Python file or a folder:

βœ… will generate a patch from file
pyment example.py

βœ… will generate a patch from folder
pyment folder/to/python/progs

βœ… will overwrite the file
pyment -w myfile.py
To run the unit-tests:

import os
from pyment import PyComment

filename = 'test.py'

c = PyComment(filename)
c.proceed()
c.diff_to_file(os.path.basename(filename) + ".patch")
for s in c.get_output_docs():
    print(s)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

min()

A

function returns the item with the lowest value, or the item with the lowest value in an iterable. If the values are strings, an alphabetically comparison is done.

x = min(5, 10)
print(x)
πŸ‘‰ 5
# Найти ΠΌΠΈΠ½ΠΈΠΌΠ°Π»Π½ΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ сравнив Π΄Π²Π° значСния
test = [1, 2, 4, 5, 6]

for i in test:
    print(min(3, i))

πŸ‘‰ 1
πŸ‘‰ 2
πŸ‘‰ 3
πŸ‘‰ 3
πŸ‘‰ 3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

math.Manhattan Distance

A

The distance between two points measured along axes at right angles. In a plane with p1 at (x1, y1) and p2 at (x2, y2), it is |x1 - x2| + |y1 - y2|. Lm distance.

Distance of { 1, 6 }, { 3, 5 }, { 2, 3 } from { -1, 5 }
πŸ‘‰ sum = (abs(1 - (-1)) + abs(6 - 5)) + (abs(3 - (-1)) + abs(5 - 5)) +
(abs(2 - (-1)) + abs(3 - 5)) = 3 + 4 + 5 = 12

Distance of { 3, 5 }, { 2, 3 } from { 1, 6 }
πŸ‘‰ sum = 12 + 3 + 4 = 19

Distance of { 2, 3 } from { 3, 5 }
πŸ‘‰ sum = 19 + 3 = 22.

def distancesum (x, y, n):
    sum = 0
		
    for i in range(n):
        for j in range(i+1,n):
            sum += (abs(x[i] - x[j]) + abs(y[i] - y[j]))
     
    return sum
 
x = [ -1, 1, 3, 2 ]
y = [ 5, 6, 5, 3 ]
n = len(x)
print(distancesum(x, y, n)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the difference between programming and scripting?

A

Programming is used to create complex software, and it is compiled. Scripting assists programming languages and it is interpreted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

git.rmdir

A

ΡƒΠ΄Π°Π»ΠΈΡ‚ΡŒ ΠΏΠ°ΠΏΠΊΡƒ.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

print(*objects , sep=’’ , end=’\n’ , file=sys.stdout , flush=False)

πŸ’‘*objects - ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Ρ‹ Python
πŸ’‘ sep=’’ - строка, Ρ€Π°Π·Π΄Π΅Π»ΠΈΡ‚Π΅Π»ΡŒ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ΠΎΠ². Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ None
πŸ’‘ end=’\n’ - строка, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΉ заканчиваСтся ΠΏΠΎΡ‚ΠΎΠΊ. Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ None
πŸ’‘ file=sys.stdout - ΠΎΠ±ΡŠΠ΅ΠΊΡ‚, Ρ€Π΅Π°Π»ΠΈΠ·ΡƒΡŽΡ‰ΠΈΠΉ ΠΌΠ΅Ρ‚ΠΎΠ΄ wrtite(string). Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ None
πŸ’‘ flush=False - Ссли True ΠΏΠΎΡ‚ΠΎΠΊ Π±ΡƒΠ΄Π΅Ρ‚ ΡΠ±Ρ€ΠΎΡˆΠ΅Π½ Π² ΡƒΠΊΠ°Π·Π°Π½Π½Ρ‹ΠΉ Ρ„Π°ΠΉΠ» file ΠΏΡ€ΠΈΠ½ΡƒΠ΄ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ.
Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ False

A

Π²Ρ‹Π²ΠΎΠ΄ΠΈΡ‚ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚Ρ‹ Π² тСкстовый ΠΏΠΎΡ‚ΠΎΠΊ, отдСляя ΠΈΡ… Π΄Ρ€ΡƒΠ³ ΠΎΡ‚ Π΄Ρ€ΡƒΠ³Π° sep ΠΈ заканчивая ΠΏΠΎΡ‚ΠΎΠΊ end. sep, end, file ΠΈ flush, Ссли ΠΎΠ½ΠΈ Π·Π°Π΄Π°Π½Ρ‹, Π΄ΠΎΠ»ΠΆΠ½Ρ‹ Π±Ρ‹Ρ‚ΡŒ ΠΏΠ΅Ρ€Π΅Π΄Π°Π½Ρ‹ Π² качСствС Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚ΠΎΠ² ΠΊΠ»ΡŽΡ‡Π΅Π²Ρ‹Ρ… слов.

print('Hello')
πŸ‘‰ Hello
print('Hello', 'how are you?')
πŸ‘‰ Hello how are you?
print('Hello', 'how are you?', sep='---')
πŸ‘‰ Hello---how are you?
lst = ['Π Π°Π·', 'Π”Π²Π°', 'Π’Ρ€ΠΈ']
for n, line in enumerate(lst, 1):
....if len(lst) == n:
........print(line)
....else:
........print(line, end='=>')

πŸ‘‰ Π Π°Π·=>Π”Π²Π°=>Π’Ρ€ΠΈ
print(11, 12, 13, 14, sep=';')
πŸ‘‰ 11;12;13;14
# использованиС символа Π½ΠΎΠ²ΠΎΠΉ строки `\n` Π² ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ 
line = 'пСрСнос строки ΠΏΡ€ΠΈ ΠΏΠ΅Ρ‡Π°Ρ‚ΠΈ\nс ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ символа Π½ΠΎΠ²ΠΎΠΉ строки'
print(line)
πŸ‘‰ пСрСнос строки ΠΏΡ€ΠΈ ΠΏΠ΅Ρ‡Π°Ρ‚ΠΈ
πŸ‘‰ с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ символа Π½ΠΎΠ²ΠΎΠΉ строки
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

numpy.busday_count(begindates, enddates, weekmask=’1111100’, holidays=[], busdaycal=None, out=None)

A

Counts the number of valid days between begindates and enddates, not including the day of enddates. If enddates specifies a date value that is earlier than the corresponding begindates date value, the count will be negative.

# Number of weekdays in January 2011
np.busday_count('2011-01', '2011-02')
πŸ‘‰ 21
# Number of weekdays in 2011
np.busday_count('2011', '2012')
πŸ‘‰ 260
# Number of Saturdays in 2011
np.busday_count('2011', '2012', weekmask='Sat')
πŸ‘‰ 53
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

os.path.commonprefix()

A

used to get longest common path prefix in a list of paths. This method returns only common prefix value in the specified list.

paths = ['/home/User/Desktop', '/home/User/Documents', '/home/User/Downloads']
prefix = os.path.commonprefix(paths)
print(prefix)

πŸ‘‰ /home/User/D
paths = ['/usr/local/bin', '/usr/bin']
prefix = os.path.commonprefix(paths)
print(prefix)

πŸ‘‰ /usr/
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

os.path.commonpath()

A

used to get the longest common sub-path in a list of paths. This method raise ValueError if the specified list of paths either contains both absolute and relative path, or is empty.

paths = ['/home/User/Desktop', '/home/User/Documents',  '/home/User/Downloads'] 
prefix = os.path.commonpath(paths)
print(prefix)

πŸ‘‰ /home/User
paths = ['/usr/local/bin', '/usr/bin']
prefix = os.path.commonpath(paths)
print(prefix)

πŸ‘‰ /usr
22
Q

numpy.random.default_rng(seed=None)

A

Construct a new Generator with the default BitGenerator (PCG64).

rng = np.random.default_rng(12345)
rfloat = rng.random()

print(rfloat)
πŸ‘‰ 0.22733602246716966
rng = np.random.default_rng(12345)
rints = rng.integers(low=0, high=10, size=3)

print(rints)
πŸ‘‰ array([6, 2, 7])
If we exit and restart our Python interpreter, we’ll see that we generate the same random 
numbers again:

rng = np.random.default_rng(seed=42)
arr2 = rng.random((3, 3))

print(arr2)
πŸ‘‰ array([[0.77395605, 0.43887844, 0.85859792],
          [0.69736803, 0.09417735, 0.97562235],
          [0.7611397 , 0.78606431, 0.12811363]])
23
Q

Skewness

A

measurement of the distortion(искаТСниС) of symmetrical distribution or asymmetry in a data set. Skewness is demonstrated on a bell curve when data points are not distributed symmetrically to the left and right sides of the median on a bell curve.

24
Q

git.nano

🎯 Ctrl+o - save the changes you’ve made to the file.
🎯 Ctrl+x - exit nano. If there are unsaved changes, you’ll be asked whether you want to save the changes.

A

open an existing file or to create a new file.

nano filename
25
Q

SQL.POW()

A

used to return a result after raising a specified exponent number to a specified base number. For example, if the base is **5 and the exponent is 2, this will return a result of 25.

SELECT POW(7, 2);
πŸ‘‰ 49
SELECT POW(3, 3);
πŸ‘‰ 27
SELECT POW(6, 0);
πŸ‘‰ 1
SELECT POW(0, 4);
πŸ‘‰ 0
26
Q

SQL.FORMAT()

A

used to format the specified value in the given format.

SELECT FORMAT(25, 'N')
SELECT FORMAT(1, 'P', 'en-US')AS [PERCENTAGE IN US FORMAT], 
    FORMAT(1, 'P', 'en-IN') AS [PERCENTAGE IN INDIA FORMAT];
DECLARE @d DATETIME = GETDATE();  
SELECT FORMAT( @d, 'dd/MM/yyyy', 'en-US' ) AS 'DateTime Result'
SELECT FORMAT(SYSDATETIME(), N'hh:mm tt');
SELECT 
    FORMAT(1, 'C', 'in-IN') AS 'INDIA', 
    FORMAT(1, 'C', 'ch-CH') AS 'CHINA', 
    FORMAT(1, 'C', 'sw-SW') AS 'SWITZERLAND', 
    FORMAT(1, 'C', 'us-US') AS 'USA';
27
Q

SQL.FLOOR()

A

returns the largest integer value that is smaller than or equal to a number.

SELECT FLOOR(25.75);
πŸ‘‰ 25
SELECT FLOOR(25.44);
πŸ‘‰ 25
SELECT FLOOR(-21.53);
πŸ‘‰ -22
28
Q

MySQL.GROUP_CONCAT()

A

used to concatenate data from multiple rows into one field.

SELECT emp_id, fname, lname, dept_id, 
GROUP_CONCAT ( strength ) as "strengths" 
FROM employee group by emp_id;
SELECT dept_id, 
GROUP_CONCAT ( DISTINCT emp_id ORDER BY emp_id  SEPARATOR', ') 
as "employees ids" 
from employee group by dept_id;
SELECT dept_id, GROUP_CONCAT ( strengths SEPARATOR '  ') as "emp-id : strengths"
FROM ( SELECT dept_id, CONCAT ( emp_id, ':', GROUP_CONCATt(strength SEPARATOR', ') )
as "strengths" FROM employee GROUP BY emp_id )as emp GROUP BY dept_id;
29
Q

MySQL.COALESCE()

A

returns the first non-null value in a list.

SELECT COALESCE(NULL, NULL, NULL, 'W3Schools.com', NULL, 'Example.com');
πŸ‘‰ W3Schools.com
SELECT COALESCE(NULL, 1, 2, 'W3Schools.com');
πŸ‘‰ 1
SELECT COALESCE(1, 2, Null, 'W3Schools.com');
πŸ‘‰ 1
30
Q

numpy.sum(a, axis=None, dtype=None, out=None, keepdims=<no>, initial=<no>, where=<no>)</no></no></no>

A

Sum of array elements over a given axis.

np.sum([0.5, 1.5])
πŸ‘‰ 2.0
np.sum([0.5, 0.7, 0.2, 1.5], dtype=np.int32)
πŸ‘‰ 1
np.sum([[0, 1], [0, 5]])
πŸ‘‰ 6
np.sum([[0, 1], [0, 5]], axis=0)
πŸ‘‰ array([0, 6])
np.sum([[0, 1], [0, 5]], axis=1)
πŸ‘‰ array([1, 5])
np.sum([[0, 1], [np.nan, 5]], where=[False, True], axis=1)
πŸ‘‰ array([1., 5.])
31
Q

numpy.dot(a, b, out=None)

A

ΠŸΡ€ΠΎΠΈΠ·Π²Π΅Π΄Π΅Π½ΠΈΠ΅ Π΄Π²ΡƒΡ… массивов.

np.dot(3, 4)
πŸ‘‰ 12
a = [[1, 0], [0, 1]]
b = [[4, 1], [2, 2]]

np.dot(a, b)
πŸ‘‰ array([[4, 1],
          [2, 2]])
32
Q

numpy.random.randint(low, high=None, size=None, dtype=int)

🎯low β€” Lowest (signed) integers to be drawn from the distribution
🎯high β€” If provided, one above the largest (signed) integer to be drawn from the distribution
🎯size β€” Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.

A

Return random integers from low (inclusive) to high (exclusive).

np.random.randint(2, size=10)
πŸ‘‰ array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0])
np.random.randint(1, size=10)
πŸ‘‰ array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
np.random.randint(5, size=(2, 4))
πŸ‘‰ array([[4, 0, 2, 1],
          [3, 2, 2, 0]])
np.random.randint([1, 3, 5, 7], [[10], [20]], dtype=np.uint8)
πŸ‘‰ array([[ 8,  6,  9,  7],
          [ 1, 16,  9, 12]], dtype=uint8)
33
Q

numpy.full(shape, fill_value, dtype=None, order=’C’, *, like=None)

A

Return a new array of given shape and type, filled with fill_value.

np.full((2, 2), np.inf)
array([[inf, inf],
       [inf, inf]])
np.full((2, 2), 10)
array([[10, 10],
       [10, 10]])
np.full((2, 2), [1, 2])
array([[1, 2],
       [1, 2]])
34
Q

numpy.reshape(a, newshape, order=’C’)

🎯a(array_like) β€” Array to be reshaped.
🎯newshape(int or tuple of ints) β€” The new shape should be compatible with the original shape.
🎯reshaped_array(ndarray) β€” This will be a new view object if possible; otherwise, it will
be a copy.

A

Gives a new shape to an array without changing its data.

np.reshape(a, (2, 3)) # C-like index ordering
array([[0, 1, 2],
       [3, 4, 5]])
np.reshape(np.ravel(a, order='F'), (2, 3), order='F')
array([[0, 4, 3],
       [2, 1, 5]])
a = np.array([[1,2,3], [4,5,6]])
np.reshape(a, 6)
array([1, 2, 3, 4, 5, 6])
np.reshape(a, 6, order='F')
array([1, 4, 2, 5, 3, 6])
35
Q

numpy.arange([start, ]stop, [step, ]dtype=None, *, like=None)

A

Return evenly spaced values within a given interval.

np.arange(3)
πŸ‘‰ array([0, 1, 2])
np.arange(3.0)
πŸ‘‰ array([ 0.,  1.,  2.])
np.arange(3,7)
πŸ‘‰ array([3, 4, 5, 6])
np.arange(3,7,2)
πŸ‘‰ array([3, 5])
36
Q

numpy.identity(n, dtype=None, *, like=None)

A

Return square array with ones on the main diagonal.

np.identity(3)
array([[1.,  0.,  0.],
       [0.,  1.,  0.],
       [0.,  0.,  1.]])
37
Q

numpy.fromfunction(function, shape, *, dtype=<class β€˜float’>, like=None, **kwargs)

A

Construct an array by executing a function over each coordinate. The resulting array therefore has a value fn(x, y, z) at coordinate (x, y, z).

np.fromfunction(lambda i, j: i == j, (3, 3), dtype=int)
array([[ True, False, False],
       [False,  True, False],
       [False, False,  True]])
np.fromfunction(lambda i, j: i + j, (3, 3), dtype=int)
array([[0, 1, 2],
       [1, 2, 3],
       [2, 3, 4]])
38
Q

numpy.fromiter(iter, dtype, count=- 1, *, like=None)

A

Create a new 1-dimensional array from an iterable object.

iterable = (x*x for x in range(5))
np.fromiter(iterable, float)
πŸ‘‰ array([  0.,   1.,   4.,   9.,  16.])
39
Q

numpy.delete(arr, obj, axis=None)

A

Return a new array with sub-arrays along an axis deleted.

arr = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])

np.delete(arr, 1, 0)
array([[ 1,  2,  3,  4],
       [ 9, 10, 11, 12]])
np.delete(arr, np.s_[::2], 1)
array([[ 2,  4],
       [ 6,  8],
       [10, 12]])

np.delete(arr, [1,3,5], None)
array([ 1,  3,  5,  7,  8,  9, 10, 11, 12])
40
Q

numpy.imag(val)

A

Return the imaginary part of the complex argument.

a = np.array([1+2j, 3+4j, 5+6j])
a.imag
πŸ‘‰ array([2.,  4.,  6.])
np.imag(1 + 1j)
πŸ‘‰ 1.0
41
Q

numpy.expand_dims(a, axis)

A

Expand the shape of an array. Insert a new axis that will appear at the axis position in the expanded array shape.

x = np.array([1, 2])

x.shape
πŸ‘‰ (2,)
y = np.expand_dims(x, axis=0)

y.shape
πŸ‘‰ (1, 2)
y = np.expand_dims(x, axis=1)

y.shape
πŸ‘‰ (2, 1)
42
Q

numpy.ravel(a, order=’C’)

A

Return a contiguous flattened array. A 1-D array, containing the elements of the input, is returned. A copy is made only if needed.

x = np.array([[1, 2, 3], [4, 5, 6]])

np.ravel(x)
array([1, 2, 3, 4, 5, 6])
43
Q

numpy.std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=<no>, *, where=<no>)</no></no>

A

Compute the standard deviation along the specified axis. Returns the standard deviation, a measure of the spread of a distribution, of the array elements. The standard deviation is computed for the flattened array by default, otherwise over the specified axis.

a = np.array([[1, 2], [3, 4]])
np.std(a)
πŸ‘‰ 1.1180339887498949

np.std(a, axis=0)
πŸ‘‰ array([1.,  1.])

np.std(a, axis=1)
πŸ‘‰ array([0.5,  0.5])
a = np.zeros((2, 512*512), dtype=np.float32)
a[0, :] = 1.0
a[1, :] = 0.1

np.std(a)
πŸ‘‰ 0.45000005
np.std(a, dtype=np.float64)
πŸ‘‰ 0.44999999925494177
a = np.array([[14, 8, 11, 10], [7, 9, 10, 11], [10, 15, 5, 10]])

np.std(a)
πŸ‘‰ 2.614064523559687

np.std(a, where=[[True], [True], [False]])
πŸ‘‰ 2.0
44
Q

numpy.nbytes

A

Total bytes consumed by the elements of the array.

x = np.zeros((3,5,2), dtype=np.complex128)
x.nbytes
πŸ‘‰ 480

np.prod(x.shape) * x.itemsize
πŸ‘‰ 480
45
Q

numpy.concatenate((a1, a2, …), axis=0, out=None, dtype=None, casting=”same_kind”)

A

Join a sequence of arrays along an existing axis.

a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])

np.concatenate((a, b), axis=0)
array([[1, 2],
       [3, 4],
       [5, 6]])
np.concatenate((a, b.T), axis=1)
array([[1, 2, 5],
       [3, 4, 6]])
np.concatenate((a, b), axis=None)
array([1, 2, 3, 4, 5, 6])
46
Q

numpy.column_stack(tup)

A

Stack 1-D arrays as columns into a 2-D array. Take a sequence of 1-D arrays and stack them as columns to make a single 2-D array. 2-D arrays are stacked as-is, just like with hstack. 1-D arrays are turned into 2-D columns first.

a = np.array((1,2,3))
b = np.array((2,3,4))

np.column_stack((a,b))
array([[1, 2],
       [2, 3],
       [3, 4]])
47
Q

numpy.mean(a, axis=None, dtype=None, out=None, keepdims=<no>, *, where=<no>)</no></no>

A

Compute the arithmetic mean along the specified axis. Returns the average of the array elements.

a = np.array([[1, 2], [3, 4]])
np.mean(a)
πŸ‘‰ 2.5
np.mean(a, axis=0)
πŸ‘‰ array([2., 3.])
np.mean(a, axis=1)
πŸ‘‰ array([1.5, 3.5])
48
Q

numpy.any(a, axis=None, out=None, keepdims=<no>, *, where=<no>)</no></no>

A

Test whether any array element along a given axis evaluates to True. Returns single boolean unless axis is not None.

np.any([[True, False], [True, True]])
πŸ‘‰ True
np.any([[True, False], [False, False]], axis=0)
πŸ‘‰ array([ True, False])
np.any([-1, 0, 5])
πŸ‘‰ True
np.any([[True, False], [False, False]], where=[[False], [True]])
πŸ‘‰ False
49
Q

numpy.unique(ar, return_index=False, return_inverse=False, return_counts=False, axis=None)

A

Find the unique elements of an array. Π’ΠΎΠ·Ρ€Π°Ρ‰Π°Π΅Ρ‚ array Π±Π΅Π· Π΄ΡƒΠ±Π»ΠΈΠΊΠ°Ρ‚ΠΎΠ².

np.unique([1, 1, 2, 2, 3, 3])
πŸ‘‰ array([1, 2, 3])
a = np.array([[1, 1], [2, 3]])
np.unique(a)
πŸ‘‰ array([1, 2, 3])
a = np.array([[1, 0, 0], [1, 0, 0], [2, 3, 4]])
np.unique(a, axis=0)
πŸ‘‰ array([[1, 0, 0], [2, 3, 4]])
50
Q

numpy.hstack(tup) and numpy.vstack(tup)

A

Stack arrays in sequence horizontally (column wise). Π‘ΠΎΠ΅Π΄ΠΈΠ½ΠΈΡ‚ΡŒ Π΄Π²Π° arrays ΠΈΠ»ΠΈ большС.
Stack arrays in sequence vertically (row wise).

a = np.array((1,2,3))
b = np.array((4,5,6))
np.hstack((a,b))
array([1, 2, 3, 4, 5, 6])
a = np.array([[1],[2],[3]])
b = np.array([[4],[5],[6]])
np.hstack((a,b))
array([[1, 4],
       [2, 5],
       [3, 6]])
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
np.vstack((a,b))
array([[1, 2, 3],
       [4, 5, 6]])
a = np.array([[1], [2], [3]])
b = np.array([[4], [5], [6]])
np.vstack((a,b))
array([[1],
       [2],
       [3],
       [4],
       [5],
       [6]])