julia_coursera/03_Coursera_1.ipynb

821 lines
15 KiB
Plaintext
Raw Permalink Normal View History

2020-05-17 04:38:06 +00:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"length(bitstring(parse(Int8,\"4\")))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"length(bitstring(Int8(4)))"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Int8"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"typeof(Int8(3))"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"11001110101100010000000000000000\""
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bitstring('α')"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2-element Array{Int64,1}:\n",
" 0\n",
" 1"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"digits(10, base = 10)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4-element Array{Int64,1}:\n",
" 0\n",
" 1\n",
" 0\n",
" 1"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"digits(10, base = 2)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"false"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"typeof(2) == typeof(4.0)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3-element Array{Int64,1}:\n",
" 4695258384\n",
" 4695258416\n",
" 4695258448"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Array{Int64}(undef,3)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3-element Array{String,1}:\n",
" #undef\n",
" #undef\n",
" #undef"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Array{String}(undef,3)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"Hello World!\""
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"greeting = \"Hello World!\""
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello World!\n"
]
}
],
"source": [
"println(greeting)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3-element Array{Int64,1}:\n",
" 1\n",
" 2\n",
" 3"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = [1,2,3]"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3-element Array{Int64,1}:\n",
" 1\n",
" 2\n",
" 3"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"b = a"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"b[2] = 5"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3-element Array{Int64,1}:\n",
" 1\n",
" 5\n",
" 3"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a[1] = 7"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3-element Array{Int64,1}:\n",
" 7\n",
" 5\n",
" 3"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"b"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3-element Array{Int64,1}:\n",
" 7\n",
" 5\n",
" 3"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c = a[:]"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"9"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a[3] = 9"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3-element Array{Int64,1}:\n",
" 7\n",
" 5\n",
" 3"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3-element Array{Int64,1}:\n",
" 7\n",
" 5\n",
" 9"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2×3 Array{Integer,2}:\n",
" #undef #undef #undef\n",
" #undef #undef #undef"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"abstypevariable = Array{Integer}(undef,2,3)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Array{Integer,2}"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"typeof(abstypevariable)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"ename": "UndefRefError",
"evalue": "UndefRefError: access to undefined reference",
"output_type": "error",
"traceback": [
"UndefRefError: access to undefined reference",
"",
"Stacktrace:",
" [1] getindex(::Array{Integer,2}, ::Int64, ::Int64) at ./array.jl:729",
" [2] top-level scope at In[35]:1"
]
}
],
"source": [
"abstypevariable[2,1]"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"length(abstypevariable)"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(2, 3)"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"size(abstypevariable)"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3,)"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"size([1,2,3])"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"abstypevariable[1,1] = 1"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5.0"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"abstypevariable[1,2] = 5.0 #5.3 not possible"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2×3 Array{Integer,2}:\n",
" 1 5 #undef\n",
" #undef #undef #undef"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"abstypevariable"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"ename": "MethodError",
"evalue": "MethodError: Cannot `convert` an object of type String to an object of type Integer\nClosest candidates are:\n convert(::Type{T<:Number}, !Matched::T<:Number) where T<:Number at number.jl:6\n convert(::Type{T<:Number}, !Matched::Number) where T<:Number at number.jl:7\n convert(::Type{T<:Integer}, !Matched::Ptr) where T<:Integer at pointer.jl:23\n ...",
"output_type": "error",
"traceback": [
"MethodError: Cannot `convert` an object of type String to an object of type Integer\nClosest candidates are:\n convert(::Type{T<:Number}, !Matched::T<:Number) where T<:Number at number.jl:6\n convert(::Type{T<:Number}, !Matched::Number) where T<:Number at number.jl:7\n convert(::Type{T<:Integer}, !Matched::Ptr) where T<:Integer at pointer.jl:23\n ...",
"",
"Stacktrace:",
" [1] setindex!(::Array{Integer,2}, ::String, ::Int64, ::Int64) at ./array.jl:768",
" [2] top-level scope at In[46]:1"
]
}
],
"source": [
"abstypevariable[2,2] = \"stringystringstr\""
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2×3 Array{Int64,2}:\n",
" 4679027904 4583513520 -1\n",
" 4661545168 1 4311744769"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arbconcretevariable = Array{Int64}(undef,2,3)"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'c': ASCII/Unicode U+0063 (category Ll: Letter, lowercase)"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Cake = 'c'"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"false"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'a' === \"a\""
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×2 Array{Integer,2}:\n",
" #undef #undef\n",
" #undef #undef\n",
" #undef #undef"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = Array{Integer,2}(undef, 3, 2)"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"11×12 Array{Int64,2}:\n",
" 4684904288 4671225872 4671226928 … 4671236288 4671236816 4671237344\n",
" 4684904336 4671225920 4671226976 4671236336 4671236864 4671237392\n",
" 4684904384 4671225968 4671227024 4671236384 4671236912 4671237440\n",
" 4684904432 4671226016 4671227504 4671236432 4671236960 4671237488\n",
" 4684904480 4671226064 4671227552 4671236480 4671237008 4671237536\n",
" 4684904528 4671226112 4671227600 … 4671236528 4671237056 4671237584\n",
" 4684904576 4671226160 4671227984 4671236576 4671237104 4671237680\n",
" 4684904624 4671226208 4671228032 4671236624 4671237152 4671237728\n",
" 4684904672 4671226448 4671228080 4671236672 4671237200 4671237776\n",
" 4684904720 4671226496 4671228464 4671236720 4671237248 4671237824\n",
" 4671176608 4671226544 4671228656 … 4671236768 4671237296 4671238352"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = Array{Int64}(undef,11, 12) \n"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Array{Int64,2}"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"typeof(x)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.2.0",
"language": "julia",
"name": "julia-1.2"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.2.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}