{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction to Python " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### [Numpy](https://numpy.org/)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 92, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['ALLOW_THREADS',\n", " 'AxisError',\n", " 'BUFSIZE',\n", " 'CLIP',\n", " 'ComplexWarning',\n", " 'DataSource',\n", " 'ERR_CALL',\n", " 'ERR_DEFAULT',\n", " 'ERR_IGNORE',\n", " 'ERR_LOG',\n", " 'ERR_PRINT',\n", " 'ERR_RAISE',\n", " 'ERR_WARN',\n", " 'FLOATING_POINT_SUPPORT',\n", " 'FPE_DIVIDEBYZERO',\n", " 'FPE_INVALID',\n", " 'FPE_OVERFLOW',\n", " 'FPE_UNDERFLOW',\n", " 'False_',\n", " 'Inf',\n", " 'Infinity',\n", " 'MAXDIMS',\n", " 'MAY_SHARE_BOUNDS',\n", " 'MAY_SHARE_EXACT',\n", " 'MachAr',\n", " 'ModuleDeprecationWarning',\n", " 'NAN',\n", " 'NINF',\n", " 'NZERO',\n", " 'NaN',\n", " 'PINF',\n", " 'PZERO',\n", " 'RAISE',\n", " 'RankWarning',\n", " 'SHIFT_DIVIDEBYZERO',\n", " 'SHIFT_INVALID',\n", " 'SHIFT_OVERFLOW',\n", " 'SHIFT_UNDERFLOW',\n", " 'ScalarType',\n", " 'Tester',\n", " 'TooHardError',\n", " 'True_',\n", " 'UFUNC_BUFSIZE_DEFAULT',\n", " 'UFUNC_PYVALS_NAME',\n", " 'VisibleDeprecationWarning',\n", " 'WRAP',\n", " '_NoValue',\n", " '_UFUNC_API',\n", " '__NUMPY_SETUP__',\n", " '__all__',\n", " '__builtins__',\n", " '__cached__',\n", " '__config__',\n", " '__dir__',\n", " '__doc__',\n", " '__file__',\n", " '__getattr__',\n", " '__git_revision__',\n", " '__loader__',\n", " '__name__',\n", " '__package__',\n", " '__path__',\n", " '__spec__',\n", " '__version__',\n", " '_add_newdoc_ufunc',\n", " '_distributor_init',\n", " '_globals',\n", " '_mat',\n", " '_pytesttester',\n", " 'abs',\n", " 'absolute',\n", " 'add',\n", " 'add_docstring',\n", " 'add_newdoc',\n", " 'add_newdoc_ufunc',\n", " 'alen',\n", " 'all',\n", " 'allclose',\n", " 'alltrue',\n", " 'amax',\n", " 'amin',\n", " 'angle',\n", " 'any',\n", " 'append',\n", " 'apply_along_axis',\n", " 'apply_over_axes',\n", " 'arange',\n", " 'arccos',\n", " 'arccosh',\n", " 'arcsin',\n", " 'arcsinh',\n", " 'arctan',\n", " 'arctan2',\n", " 'arctanh',\n", " 'argmax',\n", " 'argmin',\n", " 'argpartition',\n", " 'argsort',\n", " 'argwhere',\n", " 'around',\n", " 'array',\n", " 'array2string',\n", " 'array_equal',\n", " 'array_equiv',\n", " 'array_repr',\n", " 'array_split',\n", " 'array_str',\n", " 'asanyarray',\n", " 'asarray',\n", " 'asarray_chkfinite',\n", " 'ascontiguousarray',\n", " 'asfarray',\n", " 'asfortranarray',\n", " 'asmatrix',\n", " 'asscalar',\n", " 'atleast_1d',\n", " 'atleast_2d',\n", " 'atleast_3d',\n", " 'average',\n", " 'bartlett',\n", " 'base_repr',\n", " 'binary_repr',\n", " 'bincount',\n", " 'bitwise_and',\n", " 'bitwise_not',\n", " 'bitwise_or',\n", " 'bitwise_xor',\n", " 'blackman',\n", " 'block',\n", " 'bmat',\n", " 'bool',\n", " 'bool8',\n", " 'bool_',\n", " 'broadcast',\n", " 'broadcast_arrays',\n", " 'broadcast_to',\n", " 'busday_count',\n", " 'busday_offset',\n", " 'busdaycalendar',\n", " 'byte',\n", " 'byte_bounds',\n", " 'bytes0',\n", " 'bytes_',\n", " 'c_',\n", " 'can_cast',\n", " 'cast',\n", " 'cbrt',\n", " 'cdouble',\n", " 'ceil',\n", " 'cfloat',\n", " 'char',\n", " 'character',\n", " 'chararray',\n", " 'choose',\n", " 'clip',\n", " 'clongdouble',\n", " 'clongfloat',\n", " 'column_stack',\n", " 'common_type',\n", " 'compare_chararrays',\n", " 'compat',\n", " 'complex',\n", " 'complex128',\n", " 'complex256',\n", " 'complex64',\n", " 'complex_',\n", " 'complexfloating',\n", " 'compress',\n", " 'concatenate',\n", " 'conj',\n", " 'conjugate',\n", " 'convolve',\n", " 'copy',\n", " 'copysign',\n", " 'copyto',\n", " 'core',\n", " 'corrcoef',\n", " 'correlate',\n", " 'cos',\n", " 'cosh',\n", " 'count_nonzero',\n", " 'cov',\n", " 'cross',\n", " 'csingle',\n", " 'ctypeslib',\n", " 'cumprod',\n", " 'cumproduct',\n", " 'cumsum',\n", " 'datetime64',\n", " 'datetime_as_string',\n", " 'datetime_data',\n", " 'deg2rad',\n", " 'degrees',\n", " 'delete',\n", " 'deprecate',\n", " 'deprecate_with_doc',\n", " 'diag',\n", " 'diag_indices',\n", " 'diag_indices_from',\n", " 'diagflat',\n", " 'diagonal',\n", " 'diff',\n", " 'digitize',\n", " 'disp',\n", " 'divide',\n", " 'divmod',\n", " 'dot',\n", " 'double',\n", " 'dsplit',\n", " 'dstack',\n", " 'dtype',\n", " 'dual',\n", " 'e',\n", " 'ediff1d',\n", " 'einsum',\n", " 'einsum_path',\n", " 'emath',\n", " 'empty',\n", " 'empty_like',\n", " 'equal',\n", " 'errstate',\n", " 'euler_gamma',\n", " 'exp',\n", " 'exp2',\n", " 'expand_dims',\n", " 'expm1',\n", " 'extract',\n", " 'eye',\n", " 'fabs',\n", " 'fastCopyAndTranspose',\n", " 'fft',\n", " 'fill_diagonal',\n", " 'find_common_type',\n", " 'finfo',\n", " 'fix',\n", " 'flatiter',\n", " 'flatnonzero',\n", " 'flexible',\n", " 'flip',\n", " 'fliplr',\n", " 'flipud',\n", " 'float',\n", " 'float128',\n", " 'float16',\n", " 'float32',\n", " 'float64',\n", " 'float_',\n", " 'float_power',\n", " 'floating',\n", " 'floor',\n", " 'floor_divide',\n", " 'fmax',\n", " 'fmin',\n", " 'fmod',\n", " 'format_float_positional',\n", " 'format_float_scientific',\n", " 'format_parser',\n", " 'frexp',\n", " 'frombuffer',\n", " 'fromfile',\n", " 'fromfunction',\n", " 'fromiter',\n", " 'frompyfunc',\n", " 'fromregex',\n", " 'fromstring',\n", " 'full',\n", " 'full_like',\n", " 'fv',\n", " 'gcd',\n", " 'generic',\n", " 'genfromtxt',\n", " 'geomspace',\n", " 'get_array_wrap',\n", " 'get_include',\n", " 'get_printoptions',\n", " 'getbufsize',\n", " 'geterr',\n", " 'geterrcall',\n", " 'geterrobj',\n", " 'gradient',\n", " 'greater',\n", " 'greater_equal',\n", " 'half',\n", " 'hamming',\n", " 'hanning',\n", " 'heaviside',\n", " 'histogram',\n", " 'histogram2d',\n", " 'histogram_bin_edges',\n", " 'histogramdd',\n", " 'hsplit',\n", " 'hstack',\n", " 'hypot',\n", " 'i0',\n", " 'identity',\n", " 'iinfo',\n", " 'imag',\n", " 'in1d',\n", " 'index_exp',\n", " 'indices',\n", " 'inexact',\n", " 'inf',\n", " 'info',\n", " 'infty',\n", " 'inner',\n", " 'insert',\n", " 'int',\n", " 'int0',\n", " 'int16',\n", " 'int32',\n", " 'int64',\n", " 'int8',\n", " 'int_',\n", " 'intc',\n", " 'integer',\n", " 'interp',\n", " 'intersect1d',\n", " 'intp',\n", " 'invert',\n", " 'ipmt',\n", " 'irr',\n", " 'is_busday',\n", " 'isclose',\n", " 'iscomplex',\n", " 'iscomplexobj',\n", " 'isfinite',\n", " 'isfortran',\n", " 'isin',\n", " 'isinf',\n", " 'isnan',\n", " 'isnat',\n", " 'isneginf',\n", " 'isposinf',\n", " 'isreal',\n", " 'isrealobj',\n", " 'isscalar',\n", " 'issctype',\n", " 'issubclass_',\n", " 'issubdtype',\n", " 'issubsctype',\n", " 'iterable',\n", " 'ix_',\n", " 'kaiser',\n", " 'kernel_version',\n", " 'kron',\n", " 'lcm',\n", " 'ldexp',\n", " 'left_shift',\n", " 'less',\n", " 'less_equal',\n", " 'lexsort',\n", " 'lib',\n", " 'linalg',\n", " 'linspace',\n", " 'little_endian',\n", " 'load',\n", " 'loads',\n", " 'loadtxt',\n", " 'log',\n", " 'log10',\n", " 'log1p',\n", " 'log2',\n", " 'logaddexp',\n", " 'logaddexp2',\n", " 'logical_and',\n", " 'logical_not',\n", " 'logical_or',\n", " 'logical_xor',\n", " 'logspace',\n", " 'long',\n", " 'longcomplex',\n", " 'longdouble',\n", " 'longfloat',\n", " 'longlong',\n", " 'lookfor',\n", " 'ma',\n", " 'mafromtxt',\n", " 'mask_indices',\n", " 'mat',\n", " 'math',\n", " 'matmul',\n", " 'matrix',\n", " 'matrixlib',\n", " 'max',\n", " 'maximum',\n", " 'maximum_sctype',\n", " 'may_share_memory',\n", " 'mean',\n", " 'median',\n", " 'memmap',\n", " 'meshgrid',\n", " 'mgrid',\n", " 'min',\n", " 'min_scalar_type',\n", " 'minimum',\n", " 'mintypecode',\n", " 'mirr',\n", " 'mod',\n", " 'modf',\n", " 'moveaxis',\n", " 'msort',\n", " 'multiply',\n", " 'nan',\n", " 'nan_to_num',\n", " 'nanargmax',\n", " 'nanargmin',\n", " 'nancumprod',\n", " 'nancumsum',\n", " 'nanmax',\n", " 'nanmean',\n", " 'nanmedian',\n", " 'nanmin',\n", " 'nanpercentile',\n", " 'nanprod',\n", " 'nanquantile',\n", " 'nanstd',\n", " 'nansum',\n", " 'nanvar',\n", " 'nbytes',\n", " 'ndarray',\n", " 'ndenumerate',\n", " 'ndfromtxt',\n", " 'ndim',\n", " 'ndindex',\n", " 'nditer',\n", " 'negative',\n", " 'nested_iters',\n", " 'newaxis',\n", " 'nextafter',\n", " 'nonzero',\n", " 'not_equal',\n", " 'nper',\n", " 'npv',\n", " 'numarray',\n", " 'number',\n", " 'obj2sctype',\n", " 'object',\n", " 'object0',\n", " 'object_',\n", " 'ogrid',\n", " 'oldnumeric',\n", " 'ones',\n", " 'ones_like',\n", " 'os',\n", " 'outer',\n", " 'packbits',\n", " 'pad',\n", " 'partition',\n", " 'percentile',\n", " 'pi',\n", " 'piecewise',\n", " 'place',\n", " 'pmt',\n", " 'poly',\n", " 'poly1d',\n", " 'polyadd',\n", " 'polyder',\n", " 'polydiv',\n", " 'polyfit',\n", " 'polyint',\n", " 'polymul',\n", " 'polynomial',\n", " 'polysub',\n", " 'polyval',\n", " 'positive',\n", " 'power',\n", " 'ppmt',\n", " 'printoptions',\n", " 'prod',\n", " 'product',\n", " 'promote_types',\n", " 'ptp',\n", " 'put',\n", " 'put_along_axis',\n", " 'putmask',\n", " 'pv',\n", " 'quantile',\n", " 'r_',\n", " 'rad2deg',\n", " 'radians',\n", " 'random',\n", " 'rate',\n", " 'ravel',\n", " 'ravel_multi_index',\n", " 'real',\n", " 'real_if_close',\n", " 'rec',\n", " 'recarray',\n", " 'recfromcsv',\n", " 'recfromtxt',\n", " 'reciprocal',\n", " 'record',\n", " 'remainder',\n", " 'repeat',\n", " 'require',\n", " 'reshape',\n", " 'resize',\n", " 'result_type',\n", " 'right_shift',\n", " 'rint',\n", " 'roll',\n", " 'rollaxis',\n", " 'roots',\n", " 'rot90',\n", " 'round',\n", " 'round_',\n", " 'row_stack',\n", " 's_',\n", " 'safe_eval',\n", " 'save',\n", " 'savetxt',\n", " 'savez',\n", " 'savez_compressed',\n", " 'sctype2char',\n", " 'sctypeDict',\n", " 'sctypeNA',\n", " 'sctypes',\n", " 'searchsorted',\n", " 'select',\n", " 'set_numeric_ops',\n", " 'set_printoptions',\n", " 'set_string_function',\n", " 'setbufsize',\n", " 'setdiff1d',\n", " 'seterr',\n", " 'seterrcall',\n", " 'seterrobj',\n", " 'setxor1d',\n", " 'shape',\n", " 'shares_memory',\n", " 'short',\n", " 'show_config',\n", " 'sign',\n", " 'signbit',\n", " 'signedinteger',\n", " 'sin',\n", " 'sinc',\n", " 'single',\n", " 'singlecomplex',\n", " 'sinh',\n", " 'size',\n", " 'sometrue',\n", " 'sort',\n", " 'sort_complex',\n", " 'source',\n", " 'spacing',\n", " 'split',\n", " 'sqrt',\n", " 'square',\n", " 'squeeze',\n", " 'stack',\n", " 'std',\n", " 'str',\n", " 'str0',\n", " 'str_',\n", " 'string_',\n", " 'subtract',\n", " 'sum',\n", " 'swapaxes',\n", " 'sys',\n", " 'take',\n", " 'take_along_axis',\n", " 'tan',\n", " 'tanh',\n", " 'tensordot',\n", " 'test',\n", " 'testing',\n", " 'tile',\n", " 'timedelta64',\n", " 'trace',\n", " 'tracemalloc_domain',\n", " 'transpose',\n", " 'trapz',\n", " 'tri',\n", " 'tril',\n", " 'tril_indices',\n", " 'tril_indices_from',\n", " 'trim_zeros',\n", " 'triu',\n", " 'triu_indices',\n", " 'triu_indices_from',\n", " 'true_divide',\n", " 'trunc',\n", " 'typeDict',\n", " 'typeNA',\n", " 'typecodes',\n", " 'typename',\n", " 'ubyte',\n", " 'ufunc',\n", " 'uint',\n", " 'uint0',\n", " 'uint16',\n", " 'uint32',\n", " 'uint64',\n", " 'uint8',\n", " 'uintc',\n", " 'uintp',\n", " 'ulonglong',\n", " 'unicode',\n", " 'unicode_',\n", " 'union1d',\n", " 'unique',\n", " 'unpackbits',\n", " 'unravel_index',\n", " 'unsignedinteger',\n", " 'unwrap',\n", " 'use_hugepage',\n", " 'ushort',\n", " 'vander',\n", " 'var',\n", " 'vdot',\n", " 'vectorize',\n", " 'version',\n", " 'void',\n", " 'void0',\n", " 'vsplit',\n", " 'vstack',\n", " 'warnings',\n", " 'where',\n", " 'who',\n", " 'zeros',\n", " 'zeros_like']" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dir(np)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Numpy Basic Data Types\n", "\n", "#### Type Array" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1, 2, 3, 4])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_numbers = [1,2,3,4]\n", "simple_array = np.array(my_numbers)\n", "simple_array" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "numpy.ndarray" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(simple_array)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['T',\n", " '__abs__',\n", " '__add__',\n", " '__and__',\n", " '__array__',\n", " '__array_finalize__',\n", " '__array_function__',\n", " '__array_interface__',\n", " '__array_prepare__',\n", " '__array_priority__',\n", " '__array_struct__',\n", " '__array_ufunc__',\n", " '__array_wrap__',\n", " '__bool__',\n", " '__class__',\n", " '__complex__',\n", " '__contains__',\n", " '__copy__',\n", " '__deepcopy__',\n", " '__delattr__',\n", " '__delitem__',\n", " '__dir__',\n", " '__divmod__',\n", " '__doc__',\n", " '__eq__',\n", " '__float__',\n", " '__floordiv__',\n", " '__format__',\n", " '__ge__',\n", " '__getattribute__',\n", " '__getitem__',\n", " '__gt__',\n", " '__hash__',\n", " '__iadd__',\n", " '__iand__',\n", " '__ifloordiv__',\n", " '__ilshift__',\n", " '__imatmul__',\n", " '__imod__',\n", " '__imul__',\n", " '__index__',\n", " '__init__',\n", " '__init_subclass__',\n", " '__int__',\n", " '__invert__',\n", " '__ior__',\n", " '__ipow__',\n", " '__irshift__',\n", " '__isub__',\n", " '__iter__',\n", " '__itruediv__',\n", " '__ixor__',\n", " '__le__',\n", " '__len__',\n", " '__lshift__',\n", " '__lt__',\n", " '__matmul__',\n", " '__mod__',\n", " '__mul__',\n", " '__ne__',\n", " '__neg__',\n", " '__new__',\n", " '__or__',\n", " '__pos__',\n", " '__pow__',\n", " '__radd__',\n", " '__rand__',\n", " '__rdivmod__',\n", " '__reduce__',\n", " '__reduce_ex__',\n", " '__repr__',\n", " '__rfloordiv__',\n", " '__rlshift__',\n", " '__rmatmul__',\n", " '__rmod__',\n", " '__rmul__',\n", " '__ror__',\n", " '__rpow__',\n", " '__rrshift__',\n", " '__rshift__',\n", " '__rsub__',\n", " '__rtruediv__',\n", " '__rxor__',\n", " '__setattr__',\n", " '__setitem__',\n", " '__setstate__',\n", " '__sizeof__',\n", " '__str__',\n", " '__sub__',\n", " '__subclasshook__',\n", " '__truediv__',\n", " '__xor__',\n", " 'all',\n", " 'any',\n", " 'argmax',\n", " 'argmin',\n", " 'argpartition',\n", " 'argsort',\n", " 'astype',\n", " 'base',\n", " 'byteswap',\n", " 'choose',\n", " 'clip',\n", " 'compress',\n", " 'conj',\n", " 'conjugate',\n", " 'copy',\n", " 'ctypes',\n", " 'cumprod',\n", " 'cumsum',\n", " 'data',\n", " 'diagonal',\n", " 'dot',\n", " 'dtype',\n", " 'dump',\n", " 'dumps',\n", " 'fill',\n", " 'flags',\n", " 'flat',\n", " 'flatten',\n", " 'getfield',\n", " 'imag',\n", " 'item',\n", " 'itemset',\n", " 'itemsize',\n", " 'max',\n", " 'mean',\n", " 'min',\n", " 'nbytes',\n", " 'ndim',\n", " 'newbyteorder',\n", " 'nonzero',\n", " 'partition',\n", " 'prod',\n", " 'ptp',\n", " 'put',\n", " 'ravel',\n", " 'real',\n", " 'repeat',\n", " 'reshape',\n", " 'resize',\n", " 'round',\n", " 'searchsorted',\n", " 'setfield',\n", " 'setflags',\n", " 'shape',\n", " 'size',\n", " 'sort',\n", " 'squeeze',\n", " 'std',\n", " 'strides',\n", " 'sum',\n", " 'swapaxes',\n", " 'take',\n", " 'tobytes',\n", " 'tofile',\n", " 'tolist',\n", " 'tostring',\n", " 'trace',\n", " 'transpose',\n", " 'var',\n", " 'view']" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dir(simple_array)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(4,)\n", "4\n", "1\n" ] } ], "source": [ "print(simple_array.shape)\n", "print(simple_array.size)\n", "print(simple_array.ndim)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 2, 3, 4],\n", " [4, 5, 6, 7],\n", " [8, 9, 0, 1]])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "my_other_numbers = [[1,2,3,4],[4,5,6,7],[8,9,0,1]]\n", "other_simple_array = np.array(my_other_numbers)\n", "other_simple_array" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(3, 4)\n", "12\n", "2\n" ] } ], "source": [ "print(other_simple_array.shape)\n", "print(other_simple_array.size)\n", "print(other_simple_array.ndim)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Operations between arrays (scalar and vectorial)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "A = np.array([[1,2,3],[4,5,6],[8,9,0]])\n", "B = np.array([[2,1,5],[9,2,1],[8,7,6]])" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 2, 3],\n", " [4, 5, 6],\n", " [8, 9, 0]])" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[2, 1, 5],\n", " [9, 2, 1],\n", " [8, 7, 6]])" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 3, 4, 5],\n", " [ 6, 7, 8],\n", " [10, 11, 2]])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A + 2" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 3, 6, 9],\n", " [12, 15, 18],\n", " [24, 27, 0]])" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A * 3" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.25, 0.5 , 0.75],\n", " [1. , 1.25, 1.5 ],\n", " [2. , 2.25, 0. ]])" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A / 4" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 3, 3, 8],\n", " [13, 7, 7],\n", " [16, 16, 6]])" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A + B" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 2, 2, 15],\n", " [36, 10, 6],\n", " [64, 63, 0]])" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A * B" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 44, 26, 25],\n", " [101, 56, 61],\n", " [ 97, 26, 49]])" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A.dot(B)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 4, 8],\n", " [2, 5, 9],\n", " [3, 6, 0]])" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A.T\n", "#A.transpose()" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "matrix([[1., 2.],\n", " [4., 3.]])" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Creating arrays" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n", " 17, 18, 19])" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.arange(20) # ==> np.arange(0,20,1)\n", "a" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1. , 1.2, 1.4, 1.6, 1.8, 2. , 2.2, 2.4, 2.6, 2.8, 3. , 3.2, 3.4,\n", " 3.6, 3.8, 4. , 4.2, 4.4, 4.6, 4.8])" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.arange(1,5,0.2)\n", "a" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 1. , 1.31034483, 1.62068966, 1.93103448, 2.24137931,\n", " 2.55172414, 2.86206897, 3.17241379, 3.48275862, 3.79310345,\n", " 4.10344828, 4.4137931 , 4.72413793, 5.03448276, 5.34482759,\n", " 5.65517241, 5.96551724, 6.27586207, 6.5862069 , 6.89655172,\n", " 7.20689655, 7.51724138, 7.82758621, 8.13793103, 8.44827586,\n", " 8.75862069, 9.06896552, 9.37931034, 9.68965517, 10. ])" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b = np.linspace(1,10,30)\n", "#b = np.linspace(1,2*np.pi,50)\n", "b" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1.00000000e+001, 2.59294380e+004, 6.72335754e+007, 1.74332882e+011,\n", " 4.52035366e+014, 1.17210230e+018, 3.03919538e+021, 7.88046282e+024,\n", " 2.04335972e+028, 5.29831691e+031, 1.37382380e+035, 3.56224789e+038,\n", " 9.23670857e+041, 2.39502662e+045, 6.21016942e+048, 1.61026203e+052,\n", " 4.17531894e+055, 1.08263673e+059, 2.80721620e+062, 7.27895384e+065,\n", " 1.88739182e+069, 4.89390092e+072, 1.26896100e+076, 3.29034456e+079,\n", " 8.53167852e+082, 2.21221629e+086, 5.73615251e+089, 1.48735211e+093,\n", " 3.85662042e+096, 1.00000000e+100])" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b2 = np.logspace(1,100,30)\n", "b2" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[0. 0. 0. 0.]\n", " [0. 0. 0. 0.]\n", " [0. 0. 0. 0.]]\n" ] } ], "source": [ "a1 = np.zeros((3,4))\n", "print(a1)" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[1. 1.]\n", " [1. 1.]]\n" ] } ], "source": [ "a2 = np.ones((2,2))\n", "print(a2)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[4.65775909e-310 0.00000000e+000 0.00000000e+000]\n", " [0.00000000e+000 0.00000000e+000 0.00000000e+000]]\n" ] } ], "source": [ "a3 = np.empty((2,3))\n", "print(a3)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[1. 0. 0.]\n", " [0. 1. 0.]\n", " [0. 0. 1.]]\n" ] } ], "source": [ "a4 = np.identity(3)\n", "print(a4)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1., 0., 0.],\n", " [0., 1., 0.],\n", " [0., 0., 1.]])" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.eye(3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Modifying Dimensions" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c = np.arange(10)\n", "c" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0, 1, 2, 3, 4],\n", " [5, 6, 7, 8, 9]])" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d = c.reshape(2,5)\n", "#d = np.arange(10).reshape(2,5)\n", "d" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(10,)\n", "(2, 5)\n", "2\n", "int64\n" ] } ], "source": [ "print(c.shape)\n", "print(d.shape)\n", "print(np.ndim(d))\n", "print(d.dtype.name)" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[[ 0, 1, 2, 3, 4],\n", " [ 5, 6, 7, 8, 9],\n", " [10, 11, 12, 13, 14],\n", " [15, 16, 17, 18, 19],\n", " [20, 21, 22, 23, 24],\n", " [25, 26, 27, 28, 29],\n", " [30, 31, 32, 33, 34],\n", " [35, 36, 37, 38, 39],\n", " [40, 41, 42, 43, 44],\n", " [45, 46, 47, 48, 49]],\n", "\n", " [[50, 51, 52, 53, 54],\n", " [55, 56, 57, 58, 59],\n", " [60, 61, 62, 63, 64],\n", " [65, 66, 67, 68, 69],\n", " [70, 71, 72, 73, 74],\n", " [75, 76, 77, 78, 79],\n", " [80, 81, 82, 83, 84],\n", " [85, 86, 87, 88, 89],\n", " [90, 91, 92, 93, 94],\n", " [95, 96, 97, 98, 99]]])" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d2 = np.arange(100).reshape(2,10,5)\n", "d2" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d2.ndim" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(2, 10, 5)" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d2.shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Slicing multidimensional arrays" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[[ 0, 1, 2, 3, 4],\n", " [ 5, 6, 7, 8, 9],\n", " [10, 11, 12, 13, 14],\n", " [15, 16, 17, 18, 19],\n", " [20, 21, 22, 23, 24],\n", " [25, 26, 27, 28, 29],\n", " [30, 31, 32, 33, 34],\n", " [35, 36, 37, 38, 39],\n", " [40, 41, 42, 43, 44],\n", " [45, 46, 47, 48, 49]],\n", "\n", " [[50, 51, 52, 53, 54],\n", " [55, 56, 57, 58, 59],\n", " [60, 61, 62, 63, 64],\n", " [65, 66, 67, 68, 69],\n", " [70, 71, 72, 73, 74],\n", " [75, 76, 77, 78, 79],\n", " [80, 81, 82, 83, 84],\n", " [85, 86, 87, 88, 89],\n", " [90, 91, 92, 93, 94],\n", " [95, 96, 97, 98, 99]]])" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d2" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[[21, 22],\n", " [26, 27]]])" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d2[0:1,4:6,1:3]" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n" ] } ], "source": [ "d2[d2%2==0]\n", "print(np.ndim(d2[d2%2==0]))" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [], "source": [ "#np.mask_indices?" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33,\n", " 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67,\n", " 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99])" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d2[~d2%2==0] #negation of condition" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Stacking Arrays" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 0, 1, 2, 3],\n", " [ 4, 5, 6, 7],\n", " [ 8, 9, 10, 11],\n", " [12, 13, 14, 15]])" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.arange(16).reshape(4,4)\n", "a" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 0, 1, 2, 3],\n", " [ 4, 5, 6, 7],\n", " [ 8, 9, 10, 11],\n", " [12, 13, 14, 15],\n", " [ 0, 1, 2, 3]])" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.vstack([a,np.arange(4).reshape(1,4)])" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 0, 1, 2, 3, 0],\n", " [ 4, 5, 6, 7, 1],\n", " [ 8, 9, 10, 11, 2],\n", " [12, 13, 14, 15, 3]])" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.hstack([a,np.arange(4).reshape(4,1)])" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [], "source": [ "#np.stack?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Type Matrix" ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [], "source": [ "a = np.array([[1,2.],[4,3]])\n", "b = np.array([[1,9],[7,5]])" ] }, { "cell_type": "code", "execution_count": 81, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1., 2.],\n", " [4., 3.]])" ] }, "execution_count": 81, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 82, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 9],\n", " [7, 5]])" ] }, "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b" ] }, { "cell_type": "code", "execution_count": 87, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['T',\n", " '__abs__',\n", " '__add__',\n", " '__and__',\n", " '__array__',\n", " '__array_finalize__',\n", " '__array_function__',\n", " '__array_interface__',\n", " '__array_prepare__',\n", " '__array_priority__',\n", " '__array_struct__',\n", " '__array_ufunc__',\n", " '__array_wrap__',\n", " '__bool__',\n", " '__class__',\n", " '__complex__',\n", " '__contains__',\n", " '__copy__',\n", " '__deepcopy__',\n", " '__delattr__',\n", " '__delitem__',\n", " '__dir__',\n", " '__divmod__',\n", " '__doc__',\n", " '__eq__',\n", " '__float__',\n", " '__floordiv__',\n", " '__format__',\n", " '__ge__',\n", " '__getattribute__',\n", " '__getitem__',\n", " '__gt__',\n", " '__hash__',\n", " '__iadd__',\n", " '__iand__',\n", " '__ifloordiv__',\n", " '__ilshift__',\n", " '__imatmul__',\n", " '__imod__',\n", " '__imul__',\n", " '__index__',\n", " '__init__',\n", " '__init_subclass__',\n", " '__int__',\n", " '__invert__',\n", " '__ior__',\n", " '__ipow__',\n", " '__irshift__',\n", " '__isub__',\n", " '__iter__',\n", " '__itruediv__',\n", " '__ixor__',\n", " '__le__',\n", " '__len__',\n", " '__lshift__',\n", " '__lt__',\n", " '__matmul__',\n", " '__mod__',\n", " '__mul__',\n", " '__ne__',\n", " '__neg__',\n", " '__new__',\n", " '__or__',\n", " '__pos__',\n", " '__pow__',\n", " '__radd__',\n", " '__rand__',\n", " '__rdivmod__',\n", " '__reduce__',\n", " '__reduce_ex__',\n", " '__repr__',\n", " '__rfloordiv__',\n", " '__rlshift__',\n", " '__rmatmul__',\n", " '__rmod__',\n", " '__rmul__',\n", " '__ror__',\n", " '__rpow__',\n", " '__rrshift__',\n", " '__rshift__',\n", " '__rsub__',\n", " '__rtruediv__',\n", " '__rxor__',\n", " '__setattr__',\n", " '__setitem__',\n", " '__setstate__',\n", " '__sizeof__',\n", " '__str__',\n", " '__sub__',\n", " '__subclasshook__',\n", " '__truediv__',\n", " '__xor__',\n", " 'all',\n", " 'any',\n", " 'argmax',\n", " 'argmin',\n", " 'argpartition',\n", " 'argsort',\n", " 'astype',\n", " 'base',\n", " 'byteswap',\n", " 'choose',\n", " 'clip',\n", " 'compress',\n", " 'conj',\n", " 'conjugate',\n", " 'copy',\n", " 'ctypes',\n", " 'cumprod',\n", " 'cumsum',\n", " 'data',\n", " 'diagonal',\n", " 'dot',\n", " 'dtype',\n", " 'dump',\n", " 'dumps',\n", " 'fill',\n", " 'flags',\n", " 'flat',\n", " 'flatten',\n", " 'getfield',\n", " 'imag',\n", " 'item',\n", " 'itemset',\n", " 'itemsize',\n", " 'max',\n", " 'mean',\n", " 'min',\n", " 'nbytes',\n", " 'ndim',\n", " 'newbyteorder',\n", " 'nonzero',\n", " 'partition',\n", " 'prod',\n", " 'ptp',\n", " 'put',\n", " 'ravel',\n", " 'real',\n", " 'repeat',\n", " 'reshape',\n", " 'resize',\n", " 'round',\n", " 'searchsorted',\n", " 'setfield',\n", " 'setflags',\n", " 'shape',\n", " 'size',\n", " 'sort',\n", " 'squeeze',\n", " 'std',\n", " 'strides',\n", " 'sum',\n", " 'swapaxes',\n", " 'take',\n", " 'tobytes',\n", " 'tofile',\n", " 'tolist',\n", " 'tostring',\n", " 'trace',\n", " 'transpose',\n", " 'var',\n", " 'view']" ] }, "execution_count": 87, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dir(a)" ] }, { "cell_type": "code", "execution_count": 83, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 1., 18.],\n", " [28., 15.]])" ] }, "execution_count": 83, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a * b" ] }, { "cell_type": "code", "execution_count": 84, "metadata": {}, "outputs": [], "source": [ "A = np.matrix(a)\n", "B = np.matrix(b)" ] }, { "cell_type": "code", "execution_count": 85, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "matrix([[1, 9],\n", " [7, 5]])" ] }, "execution_count": 85, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B" ] }, { "cell_type": "code", "execution_count": 88, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['A',\n", " 'A1',\n", " 'H',\n", " 'I',\n", " 'T',\n", " '__abs__',\n", " '__add__',\n", " '__and__',\n", " '__array__',\n", " '__array_finalize__',\n", " '__array_function__',\n", " '__array_interface__',\n", " '__array_prepare__',\n", " '__array_priority__',\n", " '__array_struct__',\n", " '__array_ufunc__',\n", " '__array_wrap__',\n", " '__bool__',\n", " '__class__',\n", " '__complex__',\n", " '__contains__',\n", " '__copy__',\n", " '__deepcopy__',\n", " '__delattr__',\n", " '__delitem__',\n", " '__dict__',\n", " '__dir__',\n", " '__divmod__',\n", " '__doc__',\n", " '__eq__',\n", " '__float__',\n", " '__floordiv__',\n", " '__format__',\n", " '__ge__',\n", " '__getattribute__',\n", " '__getitem__',\n", " '__gt__',\n", " '__hash__',\n", " '__iadd__',\n", " '__iand__',\n", " '__ifloordiv__',\n", " '__ilshift__',\n", " '__imatmul__',\n", " '__imod__',\n", " '__imul__',\n", " '__index__',\n", " '__init__',\n", " '__init_subclass__',\n", " '__int__',\n", " '__invert__',\n", " '__ior__',\n", " '__ipow__',\n", " '__irshift__',\n", " '__isub__',\n", " '__iter__',\n", " '__itruediv__',\n", " '__ixor__',\n", " '__le__',\n", " '__len__',\n", " '__lshift__',\n", " '__lt__',\n", " '__matmul__',\n", " '__mod__',\n", " '__module__',\n", " '__mul__',\n", " '__ne__',\n", " '__neg__',\n", " '__new__',\n", " '__or__',\n", " '__pos__',\n", " '__pow__',\n", " '__radd__',\n", " '__rand__',\n", " '__rdivmod__',\n", " '__reduce__',\n", " '__reduce_ex__',\n", " '__repr__',\n", " '__rfloordiv__',\n", " '__rlshift__',\n", " '__rmatmul__',\n", " '__rmod__',\n", " '__rmul__',\n", " '__ror__',\n", " '__rpow__',\n", " '__rrshift__',\n", " '__rshift__',\n", " '__rsub__',\n", " '__rtruediv__',\n", " '__rxor__',\n", " '__setattr__',\n", " '__setitem__',\n", " '__setstate__',\n", " '__sizeof__',\n", " '__str__',\n", " '__sub__',\n", " '__subclasshook__',\n", " '__truediv__',\n", " '__xor__',\n", " '_align',\n", " '_collapse',\n", " '_getitem',\n", " 'all',\n", " 'any',\n", " 'argmax',\n", " 'argmin',\n", " 'argpartition',\n", " 'argsort',\n", " 'astype',\n", " 'base',\n", " 'byteswap',\n", " 'choose',\n", " 'clip',\n", " 'compress',\n", " 'conj',\n", " 'conjugate',\n", " 'copy',\n", " 'ctypes',\n", " 'cumprod',\n", " 'cumsum',\n", " 'data',\n", " 'diagonal',\n", " 'dot',\n", " 'dtype',\n", " 'dump',\n", " 'dumps',\n", " 'fill',\n", " 'flags',\n", " 'flat',\n", " 'flatten',\n", " 'getA',\n", " 'getA1',\n", " 'getH',\n", " 'getI',\n", " 'getT',\n", " 'getfield',\n", " 'imag',\n", " 'item',\n", " 'itemset',\n", " 'itemsize',\n", " 'max',\n", " 'mean',\n", " 'min',\n", " 'nbytes',\n", " 'ndim',\n", " 'newbyteorder',\n", " 'nonzero',\n", " 'partition',\n", " 'prod',\n", " 'ptp',\n", " 'put',\n", " 'ravel',\n", " 'real',\n", " 'repeat',\n", " 'reshape',\n", " 'resize',\n", " 'round',\n", " 'searchsorted',\n", " 'setfield',\n", " 'setflags',\n", " 'shape',\n", " 'size',\n", " 'sort',\n", " 'squeeze',\n", " 'std',\n", " 'strides',\n", " 'sum',\n", " 'swapaxes',\n", " 'take',\n", " 'tobytes',\n", " 'tofile',\n", " 'tolist',\n", " 'tostring',\n", " 'trace',\n", " 'transpose',\n", " 'var',\n", " 'view']" ] }, "execution_count": 88, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dir(B)" ] }, { "cell_type": "code", "execution_count": 90, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "matrix([[-0.0862069 , 0.15517241],\n", " [ 0.12068966, -0.01724138]])" ] }, "execution_count": 90, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B.I" ] }, { "cell_type": "code", "execution_count": 86, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "matrix([[15., 19.],\n", " [25., 51.]])" ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A * B" ] }, { "cell_type": "code", "execution_count": 91, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\n", "\n", "\n" ] } ], "source": [ "print(type(a))\n", "print(type(A))\n", "print(type(a * b))\n", "print(type(A * B))\n", "print(type(a * B))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }