סיכום פונקציות נפוצות בnumpy

שימו לב: על מנת להריץ את התאים ב-Live Code, יש לייבא תחילה את ספרית numpy ע”י הרצת השורת הבאה:

import numpy as np

סיכום פונקציות נפוצות בnumpy#

category

name

use

Creation

np.array(obj)

create a new ndarray from an object like a list or tuple

np.zeros(shape, dtype)

create a new ndarray filled with zeros

np.ones(shape, dtype)

create a new ndarray filled with ones

np.arange(start, stop, step)

create an ndarray with evenly spaced values

np.random.random(size)

create an ndarray with random floats in [0, 1)

np.random.randint(low, high, size)

create an ndarray with random integers in a given range

Typing

np.uint8

unsigned integer type between 0 and 255

np.int_

default integer type

Attribute access

array.shape

tuple describing the shape of the array

array.T

transpose of the array

Array manipulation

np.reshape(array, new_shape)

change the shape of an array without changing its data

np.sort(array, axis)

return a sorted copy of an array

np.clip(array, min, max)

limit values in an array to a given range

np.hstack((a, b, …))

stack arrays horizontally (column wise)

np.vstack((a, b, …))

stack arrays vertically (row wise)

Numerical operations

np.abs(array)

element wise absolute value

np.log(array)

natural logarithm, element wise

np.log2(array)

base 2 logarithm, element wise

np.log10(array)

base 10 logarithm, element wise

Aggregation

array.sum(axis)

sum of elements, optionally along an axis

array.mean(axis)

mean of elements, optionally along an axis

array.median(axis)

median value, optionally along an axis

array.max(axis)

maximum value, optionally along an axis

array.min(axis)

minimum value, optionally along an axis

array.argmax(axis)

index of the maximum value

array.argmin(axis)

index of the minimum value

np.maximum(a, b)

element wise maximum between two arrays

np.minimum(a, b)

element wise minimum between two arrays

array.any(axis)

True if any element is True

array.all(axis)

True if all elements are True

array.nonzero()

indices of non zero elements

np.histogram(array, bins)

compute histogram counts per bin