的增操作
import numpy as np
arr1=np.array([1,2,3,4])
arr1
array([1, 2, 3, 4])
arr2=np.array([[1,2,3,4],[4,5,6,7],[7,8,9,10]])
arr2
array([[ 1, 2, 3, 4],
[ 4, 5, 6, 7],
[ 7, 8, 9, 10]])
np.linspace(0,1,12)
array([0. , 0.09090909, 0.18181818, 0.27272727, 0.36363636,
0.45454545, 0.54545455, 0.63636364, 0.72727273, 0.81818182,
0.90909091, 1. ])
np.logspace(0,2,20)
array([ 1. , 1.27427499, 1.62377674, 2.06913808,
2.6366509 , 3.35981829, 4.2813324 , 5.45559478,
6.95192796, 8.8586679 , 11.28837892, 14.38449888,
18.32980711, 23.35721469, 29.76351442, 37.92690191,
48.32930239, 61.58482111, 78.47599704, 100. ])
np.zeros((2,3))
array([[0., 0., 0.],
[0., 0., 0.]])
np.eye(3)
array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])
np.diag([1,2,3,4])
array([[1, 0, 0, 0],
[0, 2, 0, 0],
[0, 0, 3, 0],
[0, 0, 0, 4]])
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-611c2e9f9310> in <module>()
----> 1 np.only(1)
AttributeError: module 'numpy' has no attribute 'only'
numpy的查操作
arr2.shape
(3, 4)
arr2.ndim
2
print(arr2.size)
print(arr2.dtype)
print(arr2.itemsize)
12
int32
4
np.float64(56)
56.0
np.int8(42.00)
42
np.bool(100)
True
np.float(True)
1.0
np.float(False)
0.0
数组的索引查找
arr2[0][3]
4
arr2[1][::2]
array([4, 6])
arr2[2][::-1]
array([10, 9, 8, 7])
arr2[0,0:3]
array([1, 2, 3])
数组的改操作
arr2.shape
(3, 4)
arr2
array([[ 1, 2, 3, 4],
[ 4, 5, 6, 7],
[ 7, 8, 9, 10]])
arr2.shape=4,3
arr2
array([[ 1, 2, 3],
[ 4, 4, 5],
[ 6, 7, 7],
[ 8, 9, 10]])
arr1.reshape(2,2)
array([[1, 2],
[3, 4]])
arr = np.arange(24).reshape(6,4)
arr
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]])
arr.ravel()
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23])
arr.flatten()
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23])
arr.flatten('F')
array([ 0, 4, 8, 12, 16, 20, 1, 5, 9, 13, 17, 21, 2, 6, 10, 14, 18,
22, 3, 7, 11, 15, 19, 23])
组合数组
arr3=np.array([5,6,7,8])
np.hstack((arr1,arr3))
array([1, 2, 3, 4, 5, 6, 7, 8])
np.vstack((arr1,arr3))
array([[1, 2, 3, 4],
[5, 6, 7, 8]])
np.concatenate((arr1,arr3),axis=0)
array([1, 2, 3, 4, 5, 6, 7, 8])
切割数组
np.hsplit(arr3,2)
[array([5, 6]), array([7, 8])]
np.vsplit(arr2,2)
[array([[1, 2, 3],
[4, 4, 5]]), array([[ 6, 7, 7],
[ 8, 9, 10]])]
np.split(arr2,2,axis=0)
[array([[1, 2, 3],
[4, 4, 5]]), array([[ 6, 7, 7],
[ 8, 9, 10]])]
numpy生成数组
np.random.random(100)
array([0.24718844, 0.25631081, 0.80067577, 0.54731458, 0.36117283,
0.35409506, 0.93534987, 0.3955897 , 0.96023968, 0.07283093,
0.38460152, 0.32126312, 0.11243594, 0.04427719, 0.3198704 ,
0.69324805, 0.65809667, 0.56638065, 0.2605794 , 0.25800996,
0.0105736 , 0.4365417 , 0.96621457, 0.33927408, 0.17270602,
0.19337334, 0.91991361, 0.43882718, 0.40966043, 0.18628396,
0.99559485, 0.3502155 , 0.60824051, 0.10612848, 0.12082128,
0.76618575, 0.61954922, 0.30636821, 0.58860138, 0.28595804,
0.2941709 , 0.12332189, 0.20924179, 0.84894743, 0.15065725,
0.56816931, 0.57481882, 0.34080779, 0.11118076, 0.10929237,
0.83424188, 0.57175953, 0.72431835, 0.29539183, 0.69768558,
0.08321358, 0.12038801, 0.22570375, 0.09181257, 0.52572284,
0.03312539, 0.80486631, 0.88326144, 0.91958205, 0.84599717,
0.43848822, 0.1616214 , 0.61502627, 0.45275592, 0.76251968,
0.05089862, 0.31412276, 0.68271425, 0.89224156, 0.45542983,
0.96602019, 0.40638755, 0.70762513, 0.8108397 , 0.19614096,
0.2148134 , 0.62651281, 0.59490532, 0.45830017, 0.80077657,
0.07317575, 0.82720599, 0.54078425, 0.34777825, 0.07037456,
0.03447458, 0.89607558, 0.59804914, 0.27251149, 0.43274248,
0.1299134 , 0.8275475 , 0.17651804, 0.48176348, 0.01105595])
np.random.rand(10,5)
array([[0.40930814, 0.72686765, 0.34531033, 0.74665089, 0.01866592],
[0.59283159, 0.84582988, 0.96926426, 0.72361921, 0.71352009],
[0.49505846, 0.08843602, 0.82311259, 0.37857897, 0.53700571],
[0.6046119 , 0.83758042, 0.45001615, 0.6199002 , 0.48148373],
[0.96798926, 0.79429274, 0.04055935, 0.15771379, 0.93376616],
[0.11577732, 0.22502262, 0.68307364, 0.67214935, 0.52101115],
[0.4445864 , 0.25920109, 0.52495957, 0.54190036, 0.84344793],
[0.57941216, 0.4034183 , 0.85349706, 0.78063958, 0.12732749],
[0.09987087, 0.04826387, 0.55949114, 0.84427642, 0.53632233],
[0.32194423, 0.73564269, 0.17128699, 0.67349555, 0.14295569]])
np.random.randint(2,10,size=[2,5])
array([[5, 2, 2, 3, 3],
[3, 9, 9, 5, 4]])
numpy矩阵操作
matr1=np.mat("1 2 3; 4 5 6; 7 8 9")
matr1
matrix([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
matr2=np.matrix([[1,2,3],[4,5,6],[7,8,9]])
matr2
matrix([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
matrl * 3
matrix([[ 3, 6, 9],
[12, 15, 18],
[21, 24, 27]])
matr1 + matr2
matrix([[ 2, 4, 6],
[ 8, 10, 12],
[14, 16, 18]])
matr1 *matr2
matrix([[ 30, 36, 42],
[ 66, 81, 96],
[102, 126, 150]])
np.dot(matr1,matr2)
matrix([[ 30, 36, 42],
[ 66, 81, 96],
[102, 126, 150]])
matr1.T
matrix([[1, 4, 7],
[2, 5, 8],
[3, 6, 9]])
matr1.H
matrix([[1, 4, 7],
[2, 5, 8],
[3, 6, 9]])
matr1.I
matrix([[ 3.15251974e+15, -6.30503948e+15, 3.15251974e+15],
[-6.30503948e+15, 1.26100790e+16, -6.30503948e+15],
[ 3.15251974e+15, -6.30503948e+15, 3.15251974e+15]])
matr1 +
b1=np.zeros((5,1))
b1
array([[0.],
[0.],
[0.],
[0.],
[0.]])
b2=np.zeros((2,1))
b2
array([[0.],
[0.]])
x1=np.random.rand(3,100)
x1
array([[0.09075179, 0.88370199, 0.83199889, 0.04744116, 0.68721374,
0.58311781, 0.11288 , 0.24893839, 0.81531071, 0.71222103,
0.89375905, 0.59052425, 0.98627323, 0.96353296, 0.87425283,
0.67430194, 0.45899067, 0.53757894, 0.50624141, 0.36537463,
0.95380124, 0.32539916, 0.68898588, 0.32824702, 0.28435253,
0.94997848, 0.58669062, 0.53601851, 0.47881328, 0.72990917,
0.84044239, 0.4380828 , 0.81877912, 0.75723523, 0.10589969,
0.52039744, 0.04590483, 0.4728243 , 0.91312636, 0.97019147,
0.16810941, 0.50001958, 0.60056108, 0.75460921, 0.11730578,
0.18484758, 0.10099991, 0.24815017, 0.05215178, 0.36729573,
0.80036701, 0.90237319, 0.02158689, 0.68502686, 0.31638834,
0.62957724, 0.57102593, 0.54838569, 0.23427159, 0.07530294,
0.36870415, 0.84582591, 0.45019794, 0.85022723, 0.65253697,
0.81090191, 0.00568165, 0.47748268, 0.33633857, 0.46457955,
0.06040323, 0.61333478, 0.96035426, 0.96863168, 0.43884528,
0.46501979, 0.78955514, 0.9082462 , 0.80754507, 0.84654668,
0.79176259, 0.74751838, 0.10436392, 0.27766827, 0.62715044,
0.92067958, 0.58810943, 0.2673307 , 0.7255051 , 0.34841905,
0.22272985, 0.4835012 , 0.52043243, 0.16089741, 0.12879645,
0.81361713, 0.24398374, 0.39667257, 0.88019389, 0.21656261],
[0.52035304, 0.59964734, 0.998757 , 0.55515882, 0.89071264,
0.77947873, 0.93431511, 0.43665775, 0.15724046, 0.78397607,
0.74356577, 0.29553457, 0.91128739, 0.02642312, 0.79619125,
0.43155187, 0.42481122, 0.68215307, 0.80254154, 0.92168613,
0.1235757 , 0.57633976, 0.8814247 , 0.62125154, 0.72678505,
0.26074828, 0.22427639, 0.70785465, 0.94384042, 0.68941709,
0.55518317, 0.34353791, 0.10656943, 0.98464071, 0.09873198,
0.40365164, 0.68010722, 0.5330508 , 0.33895388, 0.56354365,
0.14229858, 0.99457424, 0.80707672, 0.73276947, 0.88849663,
0.9434747 , 0.20282143, 0.11876634, 0.62775957, 0.11582351,
0.55979587, 0.86051176, 0.82756148, 0.9024107 , 0.76079074,
0.73371273, 0.07534024, 0.16729445, 0.59208581, 0.05901274,
0.6661174 , 0.08202901, 0.1775957 , 0.62874595, 0.15846454,
0.9363143 , 0.67306432, 0.37271314, 0.64143831, 0.64130455,
0.55898767, 0.50804191, 0.45718793, 0.50526955, 0.76704513,
0.0719934 , 0.97317384, 0.27260329, 0.85919825, 0.57231663,
0.02324961, 0.08325348, 0.48702078, 0.6851534 , 0.00999894,
0.00967839, 0.17732439, 0.85515217, 0.79999081, 0.66550277,
0.7237765 , 0.22561951, 0.33505847, 0.62355293, 0.01119863,
0.93706821, 0.55290074, 0.26730697, 0.93941605, 0.70446147],
[0.05473716, 0.43295151, 0.48678718, 0.78588709, 0.34976057,
0.33325111, 0.10712262, 0.24434897, 0.22131571, 0.52531326,
0.03782709, 0.7057494 , 0.74446263, 0.09862663, 0.93059162,
0.76295803, 0.31141833, 0.19576591, 0.65909039, 0.59023196,
0.11729661, 0.85483572, 0.2461308 , 0.38072151, 0.7016594 ,
0.36166851, 0.88862813, 0.50978632, 0.74467021, 0.49254039,
0.59550587, 0.35277551, 0.90179043, 0.08281115, 0.49090622,
0.57877392, 0.3109841 , 0.67362886, 0.59973141, 0.5479717 ,
0.02302624, 0.91402428, 0.31637967, 0.81133242, 0.21111458,
0.17015656, 0.95524465, 0.72784247, 0.32647954, 0.17085354,
0.09411069, 0.68320415, 0.28832947, 0.08238552, 0.62218028,
0.23282704, 0.88217284, 0.53919366, 0.62628224, 0.27245576,
0.08025143, 0.49869644, 0.99096383, 0.24291261, 0.63892782,
0.65377249, 0.54479842, 0.38666929, 0.06575498, 0.98990191,
0.22848868, 0.03778864, 0.83189104, 0.13228505, 0.34041914,
0.09940656, 0.29950923, 0.24743009, 0.27387232, 0.84378797,
0.71603659, 0.73478725, 0.04159784, 0.14205282, 0.69132304,
0.26753447, 0.2356801 , 0.69175197, 0.36387542, 0.28826743,
0.13641423, 0.71538195, 0.21778213, 0.76365603, 0.47846311,
0.8402201 , 0.14992677, 0.37925943, 0.06957167, 0.39843992]])
w1=np.random.rand(5,3)
w1
array([[0.13544405, 0.2642042 , 0.40369159],
[0.60637576, 0.01193582, 0.97493722],
[0.77728409, 0.99113552, 0.20378061],
[0.85093033, 0.24359386, 0.91666245],
[0.93845017, 0.05482611, 0.99765831]])
w2=np.random.rand(2,5)
w2
array([[0.53312539, 0.35278278, 0.72413746, 0.90897568, 0.46740789],
[0.98520824, 0.82671762, 0.30350308, 0.57260263, 0.16301596]])
A1=np.dot(w1,x1)+b1
A1
array([[0.17186818, 0.4529004 , 0.57307698, 0.47035692, 0.46960443,
0.41945206, 0.3053834 , 0.24772566, 0.24131586, 0.51566042,
0.33277802, 0.44296957, 0.6748841 , 0.17730065, 0.70444143,
0.51334774, 0.30012142, 0.33206862, 0.54667148, 0.53127285,
0.20918758, 0.54143476, 0.42555608, 0.36229044, 0.51378752,
0.34356226, 0.49745022, 0.46541514, 0.61483611, 0.47984315,
0.50091536, 0.29251238, 0.50310006, 0.39613938, 0.2386036 ,
0.41077736, 0.31144639, 0.4768138 , 0.4553371 , 0.50150883,
0.0696608 , 0.69947928, 0.42229529, 0.62333617, 0.33585809,
0.34299725, 0.45289034, 0.35881292, 0.30471741, 0.14932121,
0.29429706, 0.62537567, 0.33796522, 0.36446185, 0.49502597,
0.37311279, 0.45337303, 0.33614342, 0.44098712, 0.13577885,
0.25832662, 0.33755406, 0.50794193, 0.37933732, 0.38817904,
0.62113246, 0.39852651, 0.31923971, 0.24157048, 0.63197497,
0.2481071 , 0.23255431, 0.58669266, 0.31809209, 0.39951987,
0.12213472, 0.48496652, 0.29492492, 0.44694091, 0.60649828,
0.40244013, 0.41987027, 0.15960111, 0.27597444, 0.36666686,
0.23525905, 0.22164785, 0.5413976 , 0.45651972, 0.33939105,
0.2764615 , 0.41389066, 0.24693015, 0.49481942, 0.21355497,
0.69696674, 0.23964902, 0.27745441, 0.39550018, 0.37630064],
[0.11460582, 0.96511329, 0.99101188, 0.80158402, 0.76833574,
0.68779114, 0.18403734, 0.39438698, 0.71203037, 0.95337842,
0.58770793, 1.0496684 , 1.33473347, 0.68073318, 1.44689732,
1.15786746, 0.58700461, 0.52497637, 0.95912326, 0.80799451,
0.69419376, 1.03760441, 0.66826695, 0.57763575, 0.86517312,
0.93176026, 1.22478853, 0.83048712, 1.02761298, 0.93102394,
1.0968313 , 0.61367718, 1.37694886, 0.55165725, 0.5439962 ,
0.88464254, 0.33914319, 0.94981744, 1.14244386, 1.12926494,
0.12608506, 1.2061871 , 0.68224912, 1.25732111, 0.28755978,
0.28924021, 0.9949683 , 0.86149054, 0.35741346, 0.39067314,
0.58375679, 1.2235293 , 0.30407053, 0.50647541, 0.80751759,
0.61750959, 1.20721867, 0.86020456, 0.75970951, 0.3119935 ,
0.30976403, 1.00006513, 1.24123639, 0.75988632, 1.02048852,
1.14027408, 0.54262305, 0.67096085, 0.27571063, 1.25445649,
0.26606115, 0.41481679, 1.39883399, 0.72235519, 0.60714774,
0.37975118, 0.78238542, 0.79522103, 0.76693931, 1.34279676,
1.17847386, 1.17064216, 0.10965203, 0.31504176, 1.05440473,
0.8192226 , 0.58850512, 0.84672454, 0.80423294, 0.50025883,
0.27669216, 0.99332885, 0.53190072, 0.84952359, 0.5447042 ,
1.32370424, 0.30071434, 0.61347729, 0.61276895, 0.52818056],
[0.59743468, 1.3694464 , 1.73580083, 0.74726144, 1.48825166,
1.29372737, 1.03560223, 0.67607644, 0.83467449, 1.43767326,
1.43938756, 0.89573796, 1.82153084, 0.79522592, 1.65831278,
1.10732662, 0.84127265, 1.13385099, 1.32323066, 1.31779359,
0.88775757, 0.99835735, 1.45930578, 0.94846932, 1.08434976,
1.07054107, 0.85939877, 1.22210312, 1.45939707, 1.35102273,
1.32487681, 0.75289623, 0.92581613, 1.58137458, 0.28020809,
0.92251303, 0.77313205, 1.03311689, 1.16792146, 1.42432853,
0.27639825, 1.56067555, 1.33120102, 1.4781534 , 1.01482154,
1.11346498, 0.47418949, 0.45891691, 0.72926176, 0.43510656,
1.19612404, 1.69350786, 0.89576068, 1.44366035, 1.12675863,
1.26401476, 0.69829148, 0.70194016, 0.89655704, 0.1725426 ,
0.96315418, 0.84037356, 0.72789232, 1.33354142, 0.79446755,
1.69154168, 0.78253357, 0.81934463, 0.9105825 , 1.19845283,
0.64754457, 0.98797434, 1.36912654, 1.28064972, 1.17072395,
0.45306483, 1.63928998, 1.02657358, 1.53508371, 1.39719824,
0.78438236, 0.81328502, 0.57230085, 0.92385461, 0.63826259,
0.77974052, 0.68090764, 1.19632923, 1.43097364, 0.98916734,
0.91828354, 0.74521828, 0.78099197, 0.89870675, 0.2087123 ,
1.73239381, 0.76819641, 0.65055043, 1.62942668, 0.94774179],
[0.25415375, 1.29490962, 1.39748369, 0.89599558, 1.12235552,
0.99154764, 0.42184171, 0.5421819 , 0.93494722, 1.27855717,
0.9763294 , 1.22141938, 1.74365475, 0.91674326, 1.79091394,
1.37828234, 0.77951597, 0.80306178, 1.23043377, 1.07646891,
0.94924209, 1.20088065, 1.02660749, 0.77964151, 1.06218938,
1.20341012, 1.36843723, 1.09584543, 1.31996169, 1.24053289,
1.396275 , 0.77983774, 1.54932107, 0.96011672, 0.56415906,
1.07168934, 0.4897992 , 1.14967871, 1.40932526, 1.46514619,
0.19881975, 1.50560573, 0.99764793, 1.56433596, 0.50977217,
0.54309318, 1.01098684, 0.90727512, 0.49656744, 0.49737199,
0.90368713, 1.60373968, 0.48425863, 0.87825155, 1.02487768,
0.92787809, 1.31291043, 1.0016485 , 0.91766668, 0.32820266,
0.54956713, 1.19685699, 1.33472764, 1.09931165, 1.17954564,
1.51739013, 0.66818527, 0.85154035, 0.50272624, 1.45894859,
0.39701189, 0.68030048, 1.69112601, 1.06857937, 0.87232368,
0.50435885, 1.18346445, 1.0660686 , 1.14750848, 1.63323381,
1.33576212, 1.32991798, 0.24557288, 0.53338999, 1.16980688,
1.03103057, 0.75967439, 1.06989267, 1.14577807, 0.72283665,
0.49088089, 1.12214913, 0.72410263, 0.98882095, 0.55091389,
1.69079377, 0.47972863, 0.75030793, 1.04159339, 0.72111709],
[0.16830395, 1.29412428, 1.32119473, 0.85900515, 1.04269169,
0.92243354, 0.26402889, 0.5013333 , 0.99454681, 1.23544944,
0.91725365, 1.27447735, 1.71824995, 1.00407202, 1.79250724,
1.4176305 , 0.7647197 , 0.73719833, 1.17662957, 0.98226817,
1.01889205, 1.18980333, 0.94045845, 0.72193425, 1.0067138 ,
1.26662487, 1.44942335, 1.05042814, 1.24401593, 1.21416845,
1.41326321, 0.78190315, 1.6739049 , 0.84722877, 0.59455135,
1.08791632, 0.3906229 , 1.14499857, 1.47383414, 1.48806176,
0.1885363 , 1.43565601, 0.92348433, 1.55777056, 0.36941865,
0.3949554 , 1.05891105, 0.96552616, 0.40907449, 0.52149234,
0.87568629, 1.57561508, 0.35328449, 0.77453184, 0.95934921,
0.86333531, 1.42011706, 1.06173579, 0.87712966, 0.34572125,
0.46259461, 1.29579145, 1.42086852, 1.07471136, 1.25849308,
1.46456706, 0.58575612, 0.85429195, 0.41640556, 1.45872886,
0.31528617, 0.64113823, 1.75625346, 1.0686898 , 0.79351051,
0.5395188 , 1.09312136, 1.11414026, 1.0781783 , 1.66763185,
1.45866427, 1.43913982, 0.16614223, 0.4398623 , 1.27880181,
1.13145051, 0.79676162, 0.98789331, 1.0877341 , 0.65105324,
0.38479751, 1.17981837, 0.72404201, 0.94704896, 0.59882572,
1.65316751, 0.40885567, 0.76528416, 0.94693139, 0.639363 ]])
A2=np.dot(w2,A1)+b2
A2
array([[0.87436926, 3.35552075, 3.79990776, 2.29060825, 3.10666864,
2.73554327, 1.48450425, 1.48793135, 2.29896605, 3.39195641,
2.74325138, 2.96104196, 4.53777092, 2.21313582, 4.55257173,
3.39944792, 2.0422816 , 2.25783677, 3.25640783, 2.96014926,
2.33835749, 3.02534432, 2.89210475, 2.12986129, 2.80039993,
2.97299064, 3.24095857, 2.91315209, 3.52838893, 3.2577181 ,
3.54313722, 1.99196212, 3.61508895, 2.81966388, 1.31273216,
2.68174896, 1.47333352, 2.91761079, 3.46144607, 3.72447604,
0.55061459, 3.96817179, 2.76827619, 3.99632144, 1.6514106 ,
1.76946497, 2.34973923, 2.1035158 , 1.45920004, 1.22835533,
2.45972712, 4.1855915 , 1.54140983, 2.5787198 , 2.74471363,
2.57903145, 3.03042723, 2.39771094, 2.39645843, 0.76731873,
1.66021944, 2.83488742, 3.11313779, 2.9375526 , 2.80267049,
4.02214018, 1.85170574, 2.17354864, 1.5370374 , 3.65528731,
1.20328667, 1.90379972, 4.15578027, 2.82261059, 2.43876461,
1.23778929, 3.30830531, 2.67094103, 3.16745649, 4.0728529 ,
3.09426346, 3.10728446, 0.83907119, 1.61770166, 2.69069316,
2.44510014, 1.88178951, 2.88790501, 3.11322331, 2.03506217,
1.53602057, 2.68218809, 1.88145032, 2.55575767, 1.23781344,
4.40263595, 1.41729363, 1.87514167, 2.99634069, 2.02756498],
[0.6183612 , 2.61214013, 2.92628671, 2.00596028, 2.36218291,
2.09264109, 1.05191021, 1.16747942, 1.77720094, 2.66604906,
1.95915847, 2.48320395, 3.59971274, 1.66741505, 3.71118936,
2.81936538, 1.60731241, 1.68530161, 2.62947294, 2.36786641,
1.75906687, 2.57582071, 2.1557811 , 1.68644813, 2.3228679 ,
2.32925138, 2.78332638, 2.31474175, 2.85682685, 2.56074011,
2.83227508, 1.59802949, 3.07501278, 2.01417377, 1.18980981,
2.20703622, 1.16600123, 2.41350795, 2.79478992, 2.94148633,
0.401334 , 3.25612736, 2.10589829, 3.2518739 , 1.22874037,
1.29034436, 2.16418021, 1.88190184, 1.16804479, 0.97195313,
1.79577771, 3.31677931, 1.19109148, 1.84508852, 2.24050429,
1.93377509, 2.63990712, 2.00198498, 2.0030817 , 0.68835597,
1.19300704, 2.31094661, 2.74339093, 2.21133544, 2.34778176,
3.17562698, 1.55682122, 1.74474383, 1.09803978, 3.09663624,
0.9396531 , 1.36596163, 3.40462982, 2.0853367 , 1.87971804,
0.94852907, 2.47798546, 2.05161027, 2.37310138, 3.33873939,
2.61146135, 2.62440195, 0.58928617, 1.18986067, 2.30495243,
1.92051387, 1.47643081, 2.37014681, 2.38233899, 1.56818922,
1.12362814, 2.29002176, 1.45269625, 2.18316212, 1.1371304 ,
3.5444195 , 1.05920388, 1.53234873, 2.14155699, 1.61217313]])
A2.shape
(2, 100)
arr4=np.array([[3,7],[9,1]])
arr4
array([[3, 7],
[9, 1]])
arr4.sort()
arr4
array([[3, 7],
[1, 9]])
arr4.sort(axis=0)
arr4
array([[1, 7],
[3, 9]])
arr5=np.array([4,3,2,1])
arr5.argsort()
array([3, 2, 1, 0], dtype=int64)
nm=('a','b','c','c')
dv=('z','x','y','o')
ind=np.lexsort((dv,nm))
print([nm[i]+","+dv[i] for i in ind])
['a,z', 'b,x', 'c,o', 'c,y']
arr6=np.array([1,1,2,2,3,3])
np.unique(arr6)
array([1, 2, 3])
np.tile(arr6,3)
array([1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3, 1, 1, 2, 2, 3, 3])
np.repeat(arr6,3,axis=0)
array([1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3])
arr2.sum(axis=0)
array([19, 22, 25])
arr6.argmax()
4
arr7=np.array([0.1,0.9])
arr7.argmax()
1