Skip to content

Бычков Данил#5

Open
DanilBychkov wants to merge 1 commit intorailbotan:mainfrom
DanilBychkov:patch-1
Open

Бычков Данил#5
DanilBychkov wants to merge 1 commit intorailbotan:mainfrom
DanilBychkov:patch-1

Conversation

@DanilBychkov
Copy link

No description provided.

},
{
"cell_type": "code",
"source": "first = np.random.randint(-15, 15, 25).reshape(5,5)\nprint(first)\nfirst=np.array([i*i if i<0 else i for i in first.ravel()]).reshape(5,5)\nprint(first)",
Copy link
Owner

Choose a reason for hiding this comment

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

Лучше использовать flatten вместо ravel, так как ravel сохраняет ссылки на оригинальный массив. Также лучше использовать np.where или булевую индексацию

},
{
"cell_type": "code",
"source": "r, c = random.randint(3,7),random.randint(2,12)\na = np.random.randint(-15, 15, r*c).reshape(r,c)\nprint(a)\nN = r*c//2\nprint(N)\ns=set()\ncount=0\nsample=[]\nwhile True:\n i, j = random.randint(0,r-1),random.randint(0,c-1)\n if (i, j) not in s:\n s.add((i, j))\n count+=1\n sample.append(a[i][j])\n if N == count:\n break\nprint(sample)",
Copy link
Owner

Choose a reason for hiding this comment

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

Лучше использовать np.random.choice

@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