import tensorflow as tf
node1 = tf.constant(3.0, tf.float32)
node2 = tf.constant(4.0, tf.float32)
node3 = tf.add(node1, node2)
print("node1 : ", node1, "node2 : ", node2)
print("node3 : ", node3)
node1 :  tf.Tensor(3.0, shape=(), dtype=float32) node2 :  tf.Tensor(4.0, shape=(), dtype=float32)
node3 :  tf.Tensor(7.0, shape=(), dtype=float32)
#tfSession =  tf.session()
#print("tfSession.run(node1, node2) : ", tfSession.run(node1, node2))
#pring("tfSession.run(node3) : ", tfSession.run(node3))

tf.print("node1 : ", node1, ", node2 : ", node2)
tf.print("node3 : ", node3)
node1 :  3 , node2 :  4
node3 :  7
#a = tf.placeholder(tf.float32)
#b = tf.placeholder(tf.float32)
#add_node = a + b

@tf.function
def add_node(a, b):
    return a+b

a = tf.constant(4, tf.float32)
b = tf.constant(3, tf.float32)
print("add_node : ", add_node(a, b))
add_node : tf.Tensor(7.0, shape=(), dtype=float32)

# tf.add: 덧셈
print("tf.add : ", tf.add(2,3))

# tf.subtract: 뺄셈
print("tf.subtract : ", tf.subtract(2,3))

# tf.multiply: 곱셈
print("tf.multiply : ", tf.multiply(2,3))

# tf.divide: 나눗셈
print("tf.divide : ", tf.divide(2,3))

# tf.pow: n-제곱
print("tf.pow : ", tf.pow(2,3))

# tf.negative: 음수 부호
print("tf.negative : ", tf.negative(2))

# tf.abs: 절대값
print("tf.abs : ", tf.abs(-2))

# tf.sign: 부호
print("tf.sign : ", tf.sign(-2))

# tf.round: 반올림
print("tf.round : ", tf.round(1.2))

# tf.math.ceil: 올림
print("tf.ceil : ", tf.math.ceil(1.2))

# tf.floor: 내림
print("tf.floor : ", tf.floor(1.2))

# tf.math.square: 제곱
print("tf.math.square : ", tf.math.square(-2))

# tf.math.sqrt: 제곱근
A = tf.constant(4, tf.float32)
print("tf.math.sqrt : ", tf.math.sqrt(A))

# tf.maximum: 두 텐서의 각 원소에서 최댓값만 반환.
print("tf.maximum : ", tf.maximum(2, 3))

# tf.minimum: 두 텐서의 각 원소에서 최솟값만 반환.
print("tf.minimum : ", tf.minimum(2, 3))

# tf.cumsum: 누적합
x = tf.constant([2, 4, 6, 8])
print("tf.cumsum : ", tf.cumsum(x))

# tf.math.cumprod: 누적곱
x = tf.constant([2, 4, 6, 8])
print("tf.math.cumprod : ", tf.math.cumprod(x))
tf.add :  tf.Tensor(5, shape=(), dtype=int32)
tf.subtract :  tf.Tensor(-1, shape=(), dtype=int32)
tf.multiply :  tf.Tensor(6, shape=(), dtype=int32)
tf.divide :  tf.Tensor(0.6666666666666666, shape=(), dtype=float64)
tf.pow :  tf.Tensor(8, shape=(), dtype=int32)
tf.negative :  tf.Tensor(-2, shape=(), dtype=int32)
tf.abs :  tf.Tensor(2, shape=(), dtype=int32)
tf.sign :  tf.Tensor(-1, shape=(), dtype=int32)
tf.round :  tf.Tensor(1.0, shape=(), dtype=float32)
tf.ceil :  tf.Tensor(2.0, shape=(), dtype=float32)
tf.floor :  tf.Tensor(1.0, shape=(), dtype=float32)
tf.math.square :  tf.Tensor(4, shape=(), dtype=int32)
tf.math.sqrt :  tf.Tensor(2.0, shape=(), dtype=float32)
tf.maximum :  tf.Tensor(3, shape=(), dtype=int32)
tf.minimum :  tf.Tensor(2, shape=(), dtype=int32)
tf.cumsum :  tf.Tensor([ 2  6 12 20], shape=(4,), dtype=int32)
tf.math.cumprod :  tf.Tensor([  2   8  48 384], shape=(4,), dtype=int32)

 

 

be the happy Gosu.

woojja ))*

\\\\\\\\\\\\\\\\\\

 

PS) I wrote this in markdown, but.. ^^;

반응형

1. Selection Sort

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <limits.h>

#define SIZE 1000

int a[SIZE];

int swap(int *a, int *b) {
	int temp = *a;
	*a = *b;
	*b = temp;
}

int main(void) {
	int n, min, index;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) scanf("%d", &a[i]);

	for (int i = 0; i < n; i++) {
		min = INT_MAX;
		for (int j = i; j < n; j++) {
			if (min > a[j]) {
				min = a[j];
				index = j;
			}
		}
		swap(&a[i], &a[index]);
	}
	for (int i = 0; i < n; i++) {
		printf("%d", a[i]);
	}
	system("pause");
	return 0;
}

 

2. Insertion Sort

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <limits.h>

#define SIZE 1000

int a[SIZE];

int swap(int *a, int *b) {
	int temp = *a;
	*a = *b;
	*b = temp;
}

int main(void) {
	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) scanf("%d", &a[i]);

	for (int i = 0; i < n - 1; i++) {
		int j = i;
		while (j >= 0 && a[j] > a[j + 1]) {
			swap(&a[j], &a[j + 1]);
			j--;
		}
	}


	for (int i = 0; i < n; i++) {
		printf("%d", a[i]);
	}
	system("pause");
	return 0;
}

 

be the happy Gosu.

woojja ))*

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

반응형

'ETC > C, C++' 카테고리의 다른 글

[C, C++] Counting Sort  (2) 2022.02.09
[C, C++] Queue in Array, Linked List  (0) 2021.10.20
[C, C++] Stack in Array, Lined List  (0) 2021.10.20
[C, C++] Sorted Doubly Linked List  (0) 2021.10.20
python -V

Anaconda 에 Tensorflow 를 설치하는 방법입니다.

Jupyter notebook 을 사용중 Tensorflow 가 설치되지 않았다는 오류메세지가 나타난다면 Tensorflow 를 설치해야합니다.

일단 Anaconda 의 Prompt 를 실행시킵니다.

Select Anaconda Prompt.

python -V

를 입력하여 python 의 버전을 확인합니다.

그리고 일단

pip install --upgrade pip

를 입력하여 pip 를 upgrade 해줍니다.

## conda create -n tensorflow pip python={python 버전}

conda create -n tensorflow pip python=3.8

조금전에 확인한 python 버전과 함께 위 명령을 입력하여 Anaconda 에 Tensorflow 만의 가상의 사용공간을 생성해줍니다.

conda activate tensorflow

생성한 가상공간을 활성화 시킵니다.

 

이제 Tensorflow 를 설치합니다.

# CPU Version 으로 설치하려면
pip install --ignore-installed --upgrade tensorflow-cpu

# GPU Version 으로 설치하려면
pip install --ignore-installed --upgrade tensorflow-gpu


# CPU / GPU stable release version (CPU/GPU 통합버전)으로 설치하려면
pip install tensorflow

# 특정 version 으로 설치하려면
pip install tensorflow=-1.92

# unstable preview version (Preview version)으로 설치하려면
pip install tf-nightly

사용하는 network 환경에 방화벽이 설치되어 있는 경우 다음과 같은 오류가 발생한다.

connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

이런 경우에는

# 다음 명령문을 conda install 전에 입력한다.
conda config --set ssl_verify false
conda install pip tensorflow

또는 

pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org tensorflow

를 실행한다.

다음과 같은 오류가 발생한 경우라면

ERROR: Could not install packages due to an OSError: [WinError 5] 액세스가 거부되었습니다:

Anaconda prompt 를 "관리자 권한으로 실행" 으로 실행하여 진행한다.

설치 후 prompt 에서 tensorflow version 을 확인한다.

# python 실행
python

# Tensorflow version 확인
import tensorflow as tf
# _ _ 두번 입력주의
tf.__version__

# python 종료
exit()

 

행복한 고수되세요.

woojja ))*

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

반응형

+ Recent posts