{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "15eac2c8-9579-417b-bfe7-3a29443798fa",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Base.Generator{UnitRange{Int64}, var\"#1#2\"}(var\"#1#2\"(), -3:3)"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"g = (k^2 for k in -3:3)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "c5d74f1b-89ce-477d-841d-38d408319945",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7-element Vector{Int64}:\n",
" 9\n",
" 4\n",
" 1\n",
" 0\n",
" 1\n",
" 4\n",
" 9"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"collect(g)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "099ee971-b0ec-4600-a93d-4f0959323a37",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7-element Vector{Int64}:\n",
" 9\n",
" 4\n",
" 1\n",
" 0\n",
" 1\n",
" 4\n",
" 9"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"v = [k^2 for k in -3:3]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "69e50b4c-5b7d-46a0-a3c7-45497abe6091",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(9, 4, 1, 0, 1, 4, 9)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Tuple(g)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8b0bee19-2a21-48d5-8504-bbd12684134b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(9, 4, 1, 0, 1, 4, 9)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t = Tuple(k^2 for k in -3:3)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "bec8589e-6cad-402f-96c7-bf23f8b16c7c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Set{Int64} with 4 elements:\n",
" 0\n",
" 4\n",
" 9\n",
" 1"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Set(g)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "8e9f5805-b000-432f-9bab-8765bbc2625f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Set{Int64} with 4 elements:\n",
" 0\n",
" 4\n",
" 9\n",
" 1"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s = Set(k^2 for k in -3:3)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "4be8a2c7-9074-41e9-a0f9-7e80407c62ec",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Dict{Int64, Int64} with 7 entries:\n",
" 0 => 0\n",
" -1 => 1\n",
" 2 => 4\n",
" -3 => 9\n",
" -2 => 4\n",
" 3 => 9\n",
" 1 => 1"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d = Dict(k => k^2 for k in -3:3)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "b47f0d72-f30d-4334-8e20-c993dc581358",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(:comprehension, (:generator, (:call, :^, :k, 2), (:(=), :k, (:call, :(:), -3, 3))))"
]
}
],
"source": [
":([k^2 for k in -3:3]) |> Meta.show_sexpr"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "895485d8-de83-42ec-a859-feba25ef1cef",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(:call, :Tuple, (:generator, (:call, :^, :k, 2), (:(=), :k, (:call, :(:), -3, 3))))"
]
}
],
"source": [
":(Tuple(k^2 for k in -3:3)) |> Meta.show_sexpr"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "1fdce4fa-3df7-4fda-a7fe-8dfb02f2186c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(:call, :Set, (:generator, (:call, :^, :k, 2), (:(=), :k, (:call, :(:), -3, 3))))"
]
}
],
"source": [
":(Set(k^2 for k in -3:3)) |> Meta.show_sexpr"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "86cd7896-80a9-4604-83f7-82982d6d7a17",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(:call, :Dict, (:generator, (:call, :(=>), :k, (:call, :^, :k, 2)), (:(=), :k, (:call, :(:), -3, 3))))"
]
}
],
"source": [
":(Dict(k => k^2 for k in -3:3)) |> Meta.show_sexpr"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "20f99083-576f-4e87-8492-0ffaee61c028",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"true"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f(x, y) = (d = x^2+y^2; d == 0 ? d : x^2*y/d)\n",
"X = Y = range(-1, 1; length=201)\n",
"\n",
"z = [f(x, y) for y in Y, x in X]\n",
"Z = f.(X', Y)\n",
"z == Z"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "9148b7fa-6ac6-4d0c-9e02-48f0f2cb0b09",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"using Plots\n",
"surface(X, Y, Z; camera=(40, 70))"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "d2e07df2-f653-4860-9f64-37180cd5344e",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"surface(X, Y, f; camera=(40, 70))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9cb0f76e-ed78-45c9-83fd-3d5f85b16980",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"jupytext": {
"formats": "ipynb,auto:hydrogen"
},
"kernelspec": {
"display_name": "Julia 1.8.0-DEV",
"language": "julia",
"name": "julia-1.8"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}