c언어 sparse matrix 질문합니다.
글쓴이: 익명 사용자 / 작성시간: 수, 2018/10/10 - 1:25오전
* sparse matrix: 0이 아닌 값을 가진 원소들을 ordered list로 표현하면 원소들의 순서는 행의 인덱스가 증가하는 순서이며, 행의 인덱스가 같은 경우 열의 인덱스가 증가하는 순서이다.
두 행렬의 원소들의 첨자 (i,j)와 (x,y)과 주어졌을 때 원소들의 순서를 비교하는 function은 어떻게 작성할까요?
int Compare(int i, int j, int x, int y)
if((i,j) < (x,y)) return -1
else if ((i,j)>(x,y)) return 1
else return 0
이런 구조로 풀 수 있을 것 같은데요!
Forums:

(i,j)는 결국 j 입니다. (컴마 연산자 -
(i,j)는 결국 j 입니다. (컴마 연산자 - 좌변을 평가한 후 버리고, 우변을 평가하고 그 값을 결과값으로 취함)
그러니
(i,j)<(x,y)는j<y와 똑같아서 원하는 대로 동작하지 않을 거고요.저 내용만 가지고 원하는 대로 하신다면
이렇게 하시면 되겠네요
좋은 하루 되세요!
간단명료
간단명료하네요! 답변 감사드립니다!!
어떻게 할 거냐? 이전에 무엇을 할 건가를
어떻게 할 거냐? 이전에 무엇을 할 건가를 생각해보셔요.
에서 원소들의 순서 비교하는 기준은 무엇인가요?raymundo 님이 쓴 댓글 참고하시면 되겠네요.
세벌 https://sebuls.blogspot.kr/
순서비교
순서는 행부터 배열 -> 행이 같으면 앞 열부터 배열 일 때
순서상 어떤 것이 더 먼저나오는가를 알아내는 질문입니다!
참고해보세요.
코드 중간에 보시면. i,j와 x,y에 순서를 얻어서. 비교했습니다. ㅇ_ㅇ;;
http://codepad.org/fh1AAnfO
#include <stdio.h> int main() { #if 0 희소행렬 (각각이 원소) 3 12 9 0 23 2 5 17 4 ordered list 차례 목록 원소들이 배열된 리스트. 각 원소들이 일정한 순서로 배열되는 것. //열 증가 x y value 0 0 3 0 1 12 0 2 9 1 0 0 1 1 23 1 2 2 2 0 5 2 1 17 2 2 4 //행 증가 x y value 0 0 3 0 1 0 0 2 5 1 0 12 1 1 23 1 2 17 2 0 9 2 1 2 2 2 4 *희소행렬 sparse matrix: 0 이 아닌 값을 가진 원소들을 ordered list로 표현하면 원소들의 순서는 행의 인덱스가 증가하는 순서이며, 행의 인덱스가 같은 경우 열의 인덱스가 증가하는 순서이다. //---------------------------------------------------- 두 행렬의 원소들의 첨자 (i,j)와 (x,y)과 주어졌을 때 원소들의 순서를 비교하는 function은 어떻게 작성할까요? A 행렬 0 2 3 5 i j 0 0 0 0 1 3 1 0 2 1 1 5 B 행렬 7 5 3 3 x y 0 0 7 0 1 3 1 0 5 1 1 3 #endif int matrix [3][3]= { {3, 12, 9}, {0, 23, 2}, {5, 17, 4} }; int array [100][3] = {0x00,}; int i; int j; printf("열 증가\n"); for(i=0; i<3; i++) { for(j=0; j<3; j++) { printf("%d %d %d\n", i, j, matrix[i][j]); } } printf("\n"); printf("행 증가\n"); int cnt = 0; for(i=0; i<3; i++) { for(j=0; j<3; j++) { printf("%d %d %d\n", i, j, matrix[j][i]); array[cnt][0] = i; array[cnt][1] = j; array[cnt][2] = matrix[j][i]; cnt++; } } printf("\n"); printf("행 증가\n"); int MAX = cnt; int orderA = 0; int orderB = 0; for(i=0; i<MAX; i++) { printf("%d %d %d\n", array[i][0], array[i][1], array[i][2]); //i,j좌표와 값이 있는. 번호 순서 if((array[i][1] == 1) && (array[i][2] == 2)) { printf("i, j를 입력했을때. 원소의 순서 : i:%d j:%d 순서:%d <<--- 이 순서값을 비교하는게 답인듯 ㅇ_ㅇ;;\n", array[i][1], array[i][2], array[i][0]); orderA = array[i][0]; } //x,y좌표와 값이 있는. 번호 순서 if((array[i][1] == 3) && (array[i][2] == 1)) { printf("x, y를 입력했을때. 원소의 순서 : x:%d y:%d 순서:%d <<--- 이 순서값을 비교하는게 답인듯 ㅇ_ㅇ;;\n", array[i][1], array[i][2], array[i][0]); orderB = array[i][0]; } } printf("\n"); if(orderA > orderB) { printf("순서A > 순서B 를 비교 : %d > %d\n", orderA, orderB); } else if(orderA == orderB) { printf("순서A == 순서B 를 비교 : %d == %d\n", orderA, orderB); } else { printf("순서A < 순서B 를 비교: %d < %d\n", orderA, orderB); } printf("---------------------------------------------\n"); printf("여기서 2개의 행렬 순서 비교 완료 - 아래는 테스트 코드\n"); printf("---------------------------------------------\n"); printf("\n"); //--------------------------------------------- int mA [2][2]= { {0, 2}, {3, 5} }; int mB [2][2]= { {7, 5}, {3, 3} }; int aA [100] = {0x00,}; int aB [100] = {0x00,}; printf("두 행렬의 원소\n"); cnt = 0; for(i=0; i<2; i++) { for(j=0; j<2; j++) { printf("%d %d %d %d\n", i, j, mA[j][i], mB[j][i]); aA[cnt] = mA[j][i]; aB[cnt] = mB[j][i]; cnt++; } } printf("\n"); printf("두 행렬의 원소 순서를 비교 - 테스트\n"); int m; int n; MAX = 4; //원소의 갯수 cnt = 0; for(m=0; m<4; m++) { for(n=0; n<4; n++) { if(aA[cnt] > aB[cnt]) { printf("aA > aB : %d %d\n", aA[cnt], aB[cnt]); } else if(aA[cnt] == aB[cnt]) { printf("aA == aB : %d %d\n", aA[cnt], aB[cnt]); } else { printf("aA < aB : %d %d\n", aA[cnt], aB[cnt]); } cnt++; } } printf("\n"); printf("두 행렬의 원소들의 첨자 (i,j)와 (x,y)과 주어졌을 때 원소들의 값을 비교\n"); MAX = 2; //원소의 갯수 cnt = 0; for(i=0; i<MAX; i++) { for(j=0; j<MAX; j++) { if(mA[j][i] > mB[j][i]) { printf("mA > mB : %d %d [j:%d][i:%d] > [j:%d][i:%d]\n", mA[j][i], mB[j][i], j, i, j, i); } else if(mA[j][i] == mB[j][i]) { printf("mA == mB : %d %d [j:%d][i:%d] > [j:%d][i:%d]\n", mA[j][i], mB[j][i], j, i, j, i); } else { printf("mA < mB : %d %d [j:%d][i:%d] > [j:%d][i:%d]\n", mA[j][i], mB[j][i], j, i, j, i); } cnt++; } } printf("\n"); return 0; } // 열 증가 0 0 3 0 1 12 0 2 9 1 0 0 1 1 23 1 2 2 2 0 5 2 1 17 2 2 4 행 증가 0 0 3 0 1 0 0 2 5 1 0 12 1 1 23 1 2 17 2 0 9 2 1 2 2 2 4 행 증가 0 0 3 0 1 0 0 2 5 1 0 12 1 1 23 1 2 17 2 0 9 2 1 2 i, j를 입력했을때. 원소의 순서 : i:1 j:2 순서:2 <<--- 이 순서값을 비교하는게 답인듯 ㅇ_ㅇ;; 2 2 4 순서A > 순서B 를 비교 : 2 > 0 --------------------------------------------- 여기서 2개의 행렬 순서 비교 완료 - 아래는 테스트 코드 --------------------------------------------- 두 행렬의 원소 0 0 0 7 0 1 3 3 1 0 2 5 1 1 5 3 두 행렬의 원소 순서를 비교 - 테스트 aA < aB : 0 7 aA == aB : 3 3 aA < aB : 2 5 aA > aB : 5 3 aA == aB : 0 0 aA == aB : 0 0 aA == aB : 0 0 aA == aB : 0 0 aA == aB : 0 0 aA == aB : 0 0 aA == aB : 0 0 aA == aB : 0 0 aA == aB : 0 0 aA == aB : 0 0 aA == aB : 0 0 aA == aB : 0 0 두 행렬의 원소들의 첨자 (i,j)와 (x,y)과 주어졌을 때 원소들의 값을 비교 mA < mB : 0 7 [j:0][i:0] > [j:0][i:0] mA == mB : 3 3 [j:1][i:0] > [j:1][i:0] mA < mB : 2 5 [j:0][i:1] > [j:0][i:1] mA > mB : 5 3 [j:1][i:1] > [j:1][i:1]행(row) 과 열(column)
http://egloos.zum.com/hhugs/v/3762318
희소행렬(sparse matrix)을 연결 리스트로 표현 할 때의 장점을 설명해주세요..
https://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=64275324&qb=c3BhcnNlIG1hdHJpeDogMA==&enc=utf8§ion=kin&rank=3&search_sort=0&spq=0
Sparse Matrix (2) - 2차원 배열을 생성하고 희소행렬로 표현하기
http://real2won0.tistory.com/9
희소 행렬 (Sparse Matrix) :: 2006/03/16 23:28
http://jiniya.net/tt/126
희소행렬 sparse matrix 의 곱을 구하는 프로그램
https://cafe.naver.com/myprogramming/7656
Sparse Matrix and its representations | Set 1 (Using Arrays and Linked Lists)
https://www.geeksforgeeks.org/sparse-matrix-representation/
//----------------------
12.5. Sparse Matrices
http://interactivepython.org/runestone/static/CS152f17/Dictionaries/Sparsematrices.html
Ordered HTML List 05.HTML,CSS
https://blog.naver.com/itinstructor/221362734545
C 언어 동적할당을 이용하여 ordered list 구현하기
https://1jeemae.blog.me/221333759568
[ html ] ul(unordered list), ol(ordered list) HTML/CSS
https://blog.naver.com/ex122388/220981219868
HTML List tag 알아보기(unordered, ordered, definition lists)
https://blog.naver.com/peterguns/220872456010
차례 목록 [ordered list]
원소들이 배열된 리스트. 각 원소들이 일정한 순서로 배열되는 것.
https://terms.naver.com/entry.nhn?docId=831642&cid=50376&categoryId=50376
선형 리스트
https://terms.naver.com/entry.nhn?docId=827557&cid=42344&categoryId=42344
Sparse matrix manipulations
https://eigen.tuxfamily.org/dox/group__TutorialSparse.html
sparse matrix: 0 ordered list
https://www.google.com/search?num=20&source=hp&ei=yES9W7-rLJKO8gXh4LmwCw&q=sparse+matrix%3A+0+ordered+list&oq=sparse+matrix%3A+0+ordered+list&gs_l=psy-ab.12...0.0.1.80.0.0.0.0.0.0.0.0..0.0....0...1c..64.psy-ab..0.0.0....0.QCtUaC9N-UA
//
scipy.sparse.csr_matrix
https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.sparse.csr_matrix.html
Sparse matrices (scipy.sparse)
https://docs.scipy.org/doc/scipy/reference/sparse.html
Compressed Sparse Row Format (CSR)
https://www.scipy-lectures.org/advanced/scipy_sparse/csr_matrix.html
Creating a sparse matrix
http://pages.mtu.edu/~msgocken/intro/node18.html
Sparse Matricies
Mapped Matrix
https://www.boost.org/doc/libs/1_40_0/libs/numeric/ublas/doc/matrix_sparse.htm
----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.
매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.
각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com
감사합니다.
자세한 설명과 참고자료 감사합니다. 참고하겠습니다.
shint 님 글 헷갈니다. 행 우선? 열 우선?
shint 님 글 헷갈니다. 행 우선? 열 우선?
세벌 https://sebuls.blogspot.kr/
Sparse Matrix in Data Structure
you can follow this article for your doubt https://simple2code.com/data-structure-algorithm/sparse-matrix-in-data-structure/
댓글 달기