How to shuffle data at the same way EVERYTIME random.seed(42)

조회 수: 45 (최근 30일)
R G
R G 2020년 9월 27일
댓글: Steven Lord 2020년 10월 1일
Hi guys,
I am looking for a way to shuffle and split my data to test 2 methods. I use 'shuffle' before using 'spliteachlabel'.
The reason I use shuffle is that I want to test many time, but shuffle will random shuffle my data without uncontronable which make the result unfair since the data is run for each method are not the same. So I wonder that there is a way to make the shuffle function run at exactly way.
I got the similar idea in Python, but dont know how to make it in Matlab
random.seed(42)
random.shuffle(imagePaths)

답변 (1개)

David Goodmanson
David Goodmanson 2020년 9월 27일
편집: David Goodmanson 2020년 9월 27일
Hi RG
rng(12345) % for example
rand
rand
rng(12345)
rand % same values as before
rand
see help rand for more examples
  댓글 수: 2
R G
R G 2020년 10월 1일
편집: R G 2020년 10월 1일
thanks for your comment, but I think you understand wrong the idea. rand is to distribute the random number, but what I want is to shuffle the number in my array.
Steven Lord
Steven Lord 2020년 10월 1일
cards = ["A", 2:10, "J", "Q", "K"] + [" spade"; " club"; " diamond"; " heart"];
rng(12345)
order = randperm(numel(cards));
shuffledDeck1 = cards(order);
rng(12345)
order2 = randperm(numel(cards));
shuffledDeck2 = cards(order2);
isequal(shuffledDeck1, shuffledDeck2) % true

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by