ndarray는 fixed-size homogeneous multidimensional array 정도로 이해할 수 있으며, 기본적으로 vectorization과 broadcasting을 지원한다.
Python에서 제공하는list,tuple등의 시퀀스 자료형은 서로 다른 데이터타입을 저장할 수 있고(heterogeneous sequence), 크기가 자동으로 커질 수 있다. 반면에ndarray는 성능향상을 위해 같은 데이터타입만을 요소로 가질 수 있고, 크기 역시 고정되어 있다. 만약 크기를 변경하면 새로 메모리에 할당되고 이전 값은 삭제된다.
# https://wikidocs.net/14606
import numpy as np
print("x는 float64를 요소타입으로 갖는 크기 3의 1차원 배열이다.")
x = np.array((0.1,0.2,0.3))
print(x)
print(x.shape) # 차원 : 1자원 배열의 shape는 (m,)
print(x.dtype) # 요소 타입 : float64
print("y는 int32를 요소 타입으로 하는 (2,3) 크기의 2차원 배열이다.")
y = np.array(((1,2,3),(4,5,6)))
print(y)
print(y.shape) # 차원 : 2자원 배열의 shape는 (m,n) 3차원은 (p,q,r)
print(y.dtype) # 요소 타입 : int32
print("생성시 입력된 값을 통해 dtype을 추천하는데, 강제로 지정하는 것은 다음과 같다.")
z = np.array([1,2,3],dtype='float64')
print(z)
print(z.shape)
print(z.dtype)
"""_summary_
ndarray의 중요 속성을 정리하면 다음과 같다.
shape : 배열의 형태
dtype : 요소의 데이터 타입, int32, float32 등등
ndim : 차원수. x.ndim = 1, y.ndim=2 등이며 len(x.shape) 와 동일
size : 요소의 개수. shape의 모든 값의 곱. x.size = 3, y.size=6 등
itemsize : 요소 데이터 타입의 크기(byte 단위), x.itemsize=8 등
data : 실제 데이터. 직접 사용자가 접근할 필요는 없음
"""
print("초기화 관련 편의함수")
Y = np.zeros((3,3))
print(Y)
Y = np.ones((3,3),dtype='int32')
Z = np.empty((3,3))
print("\n미리 크기지정없이 순차적으로 만들때, 크기 0인 배열을 생성하고 append()를 수행")
A = np.array([])
for i in range(3):
A = np.append(A,[1,2,3])
print(A)
print("단순한 시퀀스는 range() 함수의 실수버전인 arange(from,to,step)이나 \nlinspace(from,to,npoints)를 사용하면 편리하다. \n또한 단위행렬을 위한 eye(n) 함수를 제공한다.")
print(np.arange(1,2,0.1))
#array([ 1. , 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9])
print(np.arange(10)) # start, step 생략가능. 정수로 생성
#array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
print(np.arange(10.)) # start, step 생략가능. 실수로 생성
#array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])
print(np.linspace(0.,20.,11))
#array([ 0., 2., 4., ..., 16., 18., 20.])
print(np.eye(3))
#array([[ 1., 0., 0.],
# [ 0., 1., 0.],
# [ 0., 0., 1.]])
print("\n\nshape과 dtype 변경")
msg = "ndarray는 고정된 크기를 유지하면서 shape을 변경할 수 있다. 예를 들어 크기 9의 1차원 배열을 3*3 2차원 배열로 바꿀 수 있다. \n이때 사용하는 함수는 reshape() 인데 함수 또는 메쏘드 형태로 제공한다."
print(msg)
X = np.arange(0,9,1.)
print(X)
Y = np.reshape(X,(3,3)) # 또는 Y=X.reshape((3,3))
print(Y)
#만약 자기 자신을 대상을 변경하면 shape 속성을 강제로 변경하면 된다.
X.shape = (3,3)
print(X)
print("astype() 메쏘드를 사용하면 배열에서 dtype을 바꿀 수 있다.")
a = np.arange(3);
a.astype(int) # a.astype('int34') 와 동일
a.astype('int34')
a.astype('int64')
a.astype(float) # a.astype('float64')
a.astype('float32')
a.astype('float64')
print(a)
IF(<condition is true>)
BEGIN
<execute some code>
END
ELSE IF(<different condition is true>)
BEGIN
<execute some other code>
END
ELSE
BEGIN
<execute some other other code>
END
Before we get started, some transparency about my experience with Flutter.
I am a web developer with 7 years experience in advanced java script + react. Before, I spent 10 years developing windows applications using c++. Yes, i’m a real computer nerd.
A year ago, I started working on a project that had to be cross platform (Android, iOS, Web)
As a JavaScript developer, I developed mobile apps in the past with Android Studio + JAVA that were based on a hybrid WebView. I wanted to get to the next level and build native mobile apps, and learning Kotlin + Swift seemed too complicated.
I started developing with Expo + React Native, but at a early stage I realized Expo has a glass ceiling when it comes to high level features.
I kept reading awesome things about Flutter, and one day while I was at the pool with my son, I decided to jump into the water. Not the pool water, the Flutter water!
With RN (React Native) it took me about 2 months to develop a cross platform sorted list (vertical re-orderable list with drag and drop)
So that’s the first thing I tried with flutter, and it worked pretty great out of the box!
So I decided to start the project with Flutter, and with very little experience in flutter and Dart, everything really ticked amazingly, and I was in love 💕with my new framework.
I can’t even begin to describe how great the Flutter framework is! You get tons of GUI widgets (Components if you are coming from React) That work great and are super easy to work with. Almost every customization you can think of, it’s there! And the documentation from the flutter team athttps://flutter.dev/is excellent. They have short videos for almost every widget in the framework. If you are looking for advanced tutorials, there are tons on youtube. The flutter community has grown very big, and you can find answers instantly on StackoverFlow and videos for every question you have.
My app, developed with Flutter
The developer experience is really top shelf, and the Flutter IDE for VS code is amazing, and you debug super fast with the “hot reload” feature that enables you see to see changes immediately without building again. Flutter is used with Dart, which was developed by Google, and I really love it. Everything in the language just seems so simple and intuitive, and things just make sense to me. I feel like I am using an advanced version of Javascript + TypeScript.
While Dart is a real smooth transition from JavaScript, the Flutter Widget tree takes a while to gets used to. When you see Flutter code for the first time, at least when coming from Javascript or React, you get really confused. There is definitely a learning curve, but as an experienced programmer after a few tutorials I was up and running. And when you get used to it, it’s super powerful and dynamic.
And, of-course, it’s cross platform! While I used it for the Web, Android, and iOS, it also supports Windows, Linux, and MAC! I think Flutter is a game changer in this aspect, because it means that much smaller teams can get apps to the market super fast, and reach a lot of users with support for nearly every device. There are other platforms that claim to do the same, but Flutter is the real deal.
But, things ticked a lot better on mobile than on web. That being said, I still have to say that flutter web is still great, but in my experience just not yet perfect. I am still using it now in production to run my website, and the website looks and feels awesome! But, I did find some difficulties with developing for the web, and I will share them with you at the article.
TEXT IN A FLUTTER WEBSITE IS NOT REAL TEXT 😰
You are reading through this article, and all of a sudden you remember of a sentence you want to copy and paste and send to a friend. What do you do? You simply click ctrl+f, you highlight the text, copy it, and paste on any app you desire. With Flutter web, none of these options are available, because what gets rendered on the screen is not really text, it’s actually an image. So you can’t search in it, you can’t highlight it, and you can’t copy it.
And you also don’t have a built-in browser spell check. Which means that users cannot see if the text they are typing has typos. This might seem as something small to some of you, but it’s actually what bothers me about Flutter web the most. Web users today feel free to type a lot because they know the browser has their back and will fix their typos and show them the nice red underline when they misspell. Also, developing a spell checker as a developer is very hard, especially when your users might type not only in English. There is an open Github Issue for this, but it’s on P4 which means it might take a while before it gets resolved. Regarding the text search feature, this is something that you can develop on your own, if your app has a search feature. But it won’t work for you out of the box.
Users today expect sites to load up immediately, especially on good internet connections. You see a link, you press on it, and you want to something in less than a second. If you don’t get it, you go to the next site. Everything happens super fast. But websites created with flutter, after optimization, take about 3–5 seconds to load, until you see the complete page. If you develop a nice loader (Which you can display using JAVASCRIPT / HTML before the Flutter widgets are loaded) it’s actually not that bad. This is what I did. But if your users use your app or website a lot, the slow loading time will be a bad user experience for them.
My website load
The website feels slow at times 😩
Well, my wife always claims I am super slow. So who am I to complain?
When developing for the web with Flutter, your web app feels high end, and almost all Flutter widgets that look great on the mobile, also look great on the web. They are animated, they are sharp, and generally look great. But, my website feels sluggish at times. Buttons can have delayed response, and also the animations can become slower. Overall, even though a website developed withFlutter can really look amazing, it feels less performant than pure HTML / JAVASCRIPT
UP and down Arrows don’t scroll the page
The keyboard is always faster than the mouse, and users press up and down all the time to scroll the page. Out of the box, this does not work with flutter. Pressing up and down has no effect on the scrollbar. I am assuming you can write code to fix it (Flutter has an awesome widget called GestureDetector) but it doesn’t work out of the box.
SEO
While i’m not an SEO expert, i’m not sure that web engines know how to parse content from Flutter web, espceially due to the fact that it’s not real text. Since Flutter is actually from GOOGLE which is a search company, it stands to reason that this will be solved in the near future, and Google will know how to parse Flutter content.
THE VERDICT
So, Flutter web is obviously not yet mature, and your web users won’t get the best experience out of the box if you use Flutter. While some of the things discussed here can be solved with some custom development, the investment might not be worth it.
So should you develop a website with Flutter in 2023? If you need only a website without mobile apps, the answer is obviously no. There are other Frameworks that are a lot more mature and advanced for the web than Flutter.
But if you are developing an app that needs to be cross platform, the amount of work you will save from using just one codebase is incredible and might be worth it. It really depends on what are your most important platforms and when is your release date. If most of your users will come from the web, I will definitely advise at this point to use some other framework for your website, and Flutter for your mobile apps.
If you are aiming mostly for Mobile users and you are at a stage where you want to get to the market fast, I would advise sticking with Flutter web. Some advanced users might complain and won’t like the user experience, but there is no doubt that the website design will look great and also the animations (Hoping your users have good computers).
Also, the Flutter team are working on improvements all the time, and there is a good chance that a year from now some of the issues mentioned here will be solved. Developing new apps and marketing them takes a while, so it might be worth to be patient. BUT at the same time, when marketing new apps, the user experience must be great out of the box so people will come back. And when they don’t have a spell check and can’t search text, they might be moving to the next alternative.
BIG THANKS TO THE FLUTTER TEAM!
Google really developed something amazing here, and in a few years from now, Flutter can become the most used frontend framework on all platforms, and startups will have their ideas out there super fast.
I can’t really explain how great Flutter is, you need to experience it for yourself to know what I am talking about. So, really, thank you for every person in the Flutter development team, you really developed something great here!
And also a big thank you to Johannes Milke from heyflutter.com, he has some great tutorials on youtube for Flutter! I really learned a lot from watching his videos. (Links are below)
To view my to do list app developed with Flutter, see: