Skip to content

Instantly share code, notes, and snippets.

@ananya868
Created July 27, 2021 08:15
Show Gist options
  • Save ananya868/0dd16c9b8bc0991a4705f365846f1fd7 to your computer and use it in GitHub Desktop.
Save ananya868/0dd16c9b8bc0991a4705f365846f1fd7 to your computer and use it in GitHub Desktop.
Numpy
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"id": "68ea2f2a",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np \n",
"\"\"\"can use from numpy import *, but its not preferable\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "02e79e00",
"metadata": {},
"outputs": [],
"source": [
"arr = np.arange(1000000)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "720e4376",
"metadata": {},
"outputs": [],
"source": [
"pythlist = list(range(1000000))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "6d7979a5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 746 ms\n"
]
}
],
"source": [
"%time for _ in range(10): [item*3 for item in pythlist]"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "a64976fb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 29 ms\n"
]
}
],
"source": [
"%time for _ in range(10): arr = arr*3"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "63a0177a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 2, 3, 4, 5, 6])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.array([1,2,3,4,5,6])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment