Skip to content

дз numpy#4

Open
G61G612281337 wants to merge 1 commit intorailbotan:mainfrom
G61G612281337:main
Open

дз numpy#4
G61G612281337 wants to merge 1 commit intorailbotan:mainfrom
G61G612281337:main

Conversation

@G61G612281337
Copy link

Котов Илья

Котов Илья
"\n",
"mask = np.random.uniform(2, -12, (5, 5)) \n",
"matrix = np.copy(mask)\n",
"for i in range(5):\n",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вместо цикла можно воспользоваться np.tria

"source": [
"mask = np.reshape(np.random.normal(10, 2, 25), (5, 5))\n",
"matrix = np.copy(mask)\n",
"for i in range(5):\n",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вместо цикла можно воспользоваться np.fill_diagonal

"print(a)\n",
"b = np.random.randint(0,2,5)\n",
"print(b)\n",
"equal = sum(a == b) == len(a)\n",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np.array_equal

"cell_type": "code",
"source": [
"a = np.array([1, np.NaN, np.Inf, np.NaN], float)\n",
"for i in range(a.shape[0]):\n",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вместо цикла используем булевую индексацию или np.where

"axis = random.randint(1, 32) #maximum supported dimension for an ndarray is 32, found 48\n",
"print(axis)\n",
"matrix = np.zeros(tuple(np.ones((axis), dtype=int)))\n",
"print(len(matrix.shape))"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matrix.ndim

@railbotan
Copy link
Owner

5 баллов

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants